# 작성
from django.http import HttpResponse
def index(request) :
return HttpResponse("Hello, world. You're at the polls index.")
# 나의 해석
django.http라는 기능모음에서 HttpResponse 기능을 꺼내 사용한다.
index라는 함수를 만든다(def). 요청이 들어오면(request) 작동한다.
작동되면 Http응답(response)을 보낸다(return). 그 내용은 ("Hello, ~index.") 이다.
[polls - urls.py 작성]
polls 폴더에 새파일 urls.py를 만든다.
그 안에 작성한다.
이 작업으로 url경로를 응답이 들어오면, views를 출력하도록 만든다.
# 작성
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
# 나의 해석
django.urls 기능모음에서 path기능을 꺼내쓴다.
. 기능모음에서 views기능을 꺼내쓴다.
주소패턴(urlpatterns)은 경로(path)를 불러온다.
전체경로에 빈칸(''), 즉 다른 주소가 안 붙으면, views에서 index함수를 불러온다. == 127.0.0.1 : 8000 이면 출력된다.
url경로의 이름은 index 이다.
# 작성
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
#해석
기존에 작성되어있는 admin은 관리자 부분이므로, 일단 패스.
django.urls 기능모음에서 include와 path를 사용할 것
주소패턴(urlpatterns)은 첫번째경로는 127.0.0.1:8000/polls/로 들어오면 polls.urls로 전송할 것.
두번째는 +admin/ 으로 들어오면 관리자페이지로 들어갈 것.