Django 설치
pip install django
프로젝트 생성
django-admin startproject firstpjt .
서버 실행
python manage.py runserver

앱 생성
python manage.py startapp articles
앱 등록
# settings.py
INSTALLED_APPS = [
'articles',
...
]
firstpjt 폴더 내부)settings.py: 프로젝트의 모든 설정을 관리urls.py: 요청 들어오는 URL에 따라 이에 해당하는 적절한 views를 연결__init__.py: 해당 폴더를 패키지로 인식하도록 설정하는 파일asgi.py: 비동기식 웹 서버와의 연결 관련 설정wsgi.py: 웹 서버와의 연결 관련 설정manage.py: Django 프로젝트와 다양한 방법으로 상호작용하는 커맨드라인 유틸리티articles 폴더 내부)admin.py: 관리자용 페이지 설정models.py: DB와 관련된 Model을 정의 (MTV 패턴의 M)views.py: url, model, template과 연동하여 HTTP의 요청을 처리하고 해당 요청에 대한 응답을 반환 (MTV 패턴의 V)apps.py: 앱의 정보가 작성된 곳tests.py: 프로젝트 테스트 코드를 작성하는 곳사용자가 서버에 접속하는 과정

URLs
# urls.py
from django.contrib import admin
from django.urls import path
from articles import views
urlpatterns = [
path('admin/', admin.site.urls),
path('articles/', views.index),
]
/(slash)로 끝나야 함View
# views.py
from django.shortcuts import render
def index(request):
return render(request, 'articles/index.html')
Template
Django에서 template을 인식하는 경로 규칙
app폴더/templates/articles/index.html
app폴더 / templates /→ 이 지점까지 기본 경로로 인식view 함수에서 template 경로 작성 시 해당 지점 이후의 경로를 작성해야 함
from django.shortcuts import render def index(request): return render(request, 'articles/index.html')
요청 후 응답 페이지 확인
URLs : path('articles/', view.index),
View : def index(request):
return render(request, 'articles/index.html')
Template : articles/templates/articles/index.html