목록Python_Django (50)
hyeonga_code
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/wClkB/btssbhhtm7p/DD9ycl0UN7ubg8ZQWITj7k/img.jpg)
- Context - Http에 테이블 정보 전달 - context : Mapping [str,Any] - return render(request, '앱이름/참조파일.html',context) 1. > 'views.py' 'views.py' ===== 1 2 3 4 5 6 7 8 9 10 11 from django.shortcuts import render from .models import 클래스이름 def 실행함수(request): 변수 = 클래스이름.objects.all() context = { '변수세트' : 변수 } return render(request, '앱이름/참조파일.html', context) cs 2. > > '참조파일.html' '참조파일.html' ===== 1 2 3 4 5 6 ..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/lwbTy/btssquZO3Gk/g6tunhCJE4lwd5GBRmCJo0/img.jpg)
- Admin 생성 1. > 'admin.py' 'admin.py' ===== 1 2 3 4 5 6 7 8 9 10 11 from django.contrib import admin from .models import 클래스이름 # Register your models here. admin.site.register(클래스이름) Colored by Color Scripter cs 2. 터미널 @ python manage.py createsuperuser ===== ''' (mysite) C:\Users\hyeon\mysite\06_if,for> python manage.py createsuperuser Username (leave blank to use 'hyeon'): admin Email address:..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/ble5UW/btssk0ShohY/pPlPv98opZAO65gfDFmqS1/img.jpg)
- 테이블_페이지 1. 장고 실행 2. 앱 생성 3. > 'urls.py' 'urls.py' ===== 1 2 3 4 5 6 7 from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('함수이름/', include('앱이름.html')) ] Colored by Color Scripter cs 4. > 'views.py' 'views.py' ===== 1 2 3 4 5 6 from django.shortcuts import render # Create your views here. def 함수이름(request): return render(..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/BigCT/btssbljVuE7/GmsakPzHfqBD6A5oWCsuIK/img.jpg)
- 테이블 생성 - 03_앱생성 1. > 'settings.py' 'settings.py' ===== 1 2 3 4 5 6 7 8 9 INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', '앱이름.apps.앱이름_첫글자대문자 + Config' ] Colored by Color Scripter cs 2. > 'models.py' 'models.py' ===== 1 2 3 4 5 6 from django.db import models clas..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/bHA0uR/btssfEDcj6d/1E7N3goPGnF3H43u28Z130/img.jpg)
- URL_분리 - 시간 단축을 위함 - render 1) 'settings.py' > Template = [ DIR = [BASE_DIR/'templates']] 2) 'urls.py' > from 앱이름 import views > path('함수이름/', views.'참조파일.html') 3) > > '참조파일.html' > 참조파일 내용 입력 1. 폴더에 폴더 생성 2. 폴더에 폴더 생성 - '참조파일.html' 이동 3. > 'settings.py' 'settings.py' ===== 1 2 3 4 5 6 7 8 9 10 11 12 TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ 'BASE..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/bEtlJd/btssgLuM5d6/pmo4H5DiqJSGq0kKxTgblk/img.jpg)
- Render 1. '바탕폴더' 생성 2. 장고 실행 3. 가상화 4. '앱이름' 앱 생성 5. > 'views.py' 'views.py' ===== 1 2 3 4 5 6 7 from django.shortcuts import render def 함수이름(request): return render(request, '참조파일.html') cs 6. '참조파일.html' 생성 '참조파일.html' ===== 1 참조파일 내용 작성 cs 7. > 'settings.py' 'settings.py' ===== 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 TEMPLATES = [ { 'BACKEND': 'dj..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/bUEDrO/btssql2S8MZ/iEUX9IS2LOyYyI2KFAKZLK/img.jpg)
- URL_글씨 출력 - 모든 장고 요청은 url을 통해 이루어짐 1. > > 'settings.py' ===== ROOT_URLCONF = 'config.urls' 확인만 2. > > 함수 작성 'views.py' ===== 1 2 3 4 5 6 7 8 9 10 11 12 13 from django.shortcuts import render from django.http import HttpResponse _ 페이지에 글씨 출력하고 싶을 경우 def '함수이름'(request): return HttpResponse( '출력하고싶은내용' ) Colored by Color Scripter cs 3. > > 'urlpatterns' - path('실행이름/', admin.site.urls) - 리스트이므로 ..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/bTXlsm/btssqn7s2eK/mQuw6hJluEKpPXQevPknhk/img.jpg)
1 2 3 4 5 6 7 8 9 10 11 - 앱 생성 - 폴더 확인 1. > mys _ 가상 환경 접속 2. > python manage.py startapp '앱이름' 3. 폴더 생성됨 cs
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/UPU5e/btsshmatrvC/Zk4uCSOXQOPakAmRCvOQxK/img.jpg)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 - 장고 실행 1. [ Ctrl ] + [ Shift ] + [ ` ] _ 터미널 실행 2. 'PS' > 'Command Prompt' 변경 3. > pip install django 4. > pip list 5. > django-admin startproject config . _ 장고 프로그램 실행 >> 폴더 생성 된 것 확인 가능 6. > mys 7. python manage.py runserver 8. IP 주소 실행 [ Ctrl ] + 링크 >> 로켓 화면 실행됨 9. [ Ctrl ] + [ c ] _ 실행 종료 cs
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/o8GaU/btssf1ZdzjD/ohZML9Cqygkm3wsTu8V1KK/img.jpg)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 - 가상 환경 설치 1. 터미널 창 실행 2. > python -m venv mysite _ 로컬 디스크에 폴더 생성 3. > cd mysite 4. > cd Scripts 5. > activate 6. > pip list 7. > C:\mysite\Scripts\activate _ 매번 실행하기 어려우므로 메모장에 입력 후, 바탕 폴더에 'mys.cmd' 파일로 저장 8. > mys _ 위치 확인 불가 오류 8-1. [ win ] + [ r ] > sysdm.cpl > 고급 > 환경 변수 8-2. path > 추가 > 새로 만들기 > 'c:\mysit..