Django
Django(hello/hello01)
FnMask
2020. 11. 21. 14:19
python manage.py startapp hello01
#hello01이라는 앱을 만들어줍니다.
#projcet와 app의 차이점=
#http://tv.nate.com, http://web.nate.com, ...등등
#nate라는 커다란 프로젝트 안에 tv, web, tan 등등의 많은 app이 있습니다.
hello>hello01>views.py
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("<h1><a href='/heelo01/test'>Hello, Django!</a></h1>
#hello01/test로 갑니다.
hello>hello01>urls.py(만들어주세요 hello>urls.py에 넣어도 되지만 그렇게하면 지저분해지기 때문에 hello>urls.pydp 에 임포트합니다.)
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index')
]
hello>urls.py
(17번째 줄) from django.urls import path, include
#include추가해주세요
(23번째줄)path('hello01/', include('hello01.urls')),
#path를 추가해주세요
#hello01에 있는 urls 라는 파일을 hello01 이라고 요청하면 연결시켜 줄겁니다.
결과화면입니다.

----------------------------------------------------------------------------------------------------------------------------------
Hello, Django를 클릭했을 때 test라는 화면이 나오도록 만들어보겠습니다.
hello01>views.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse("<h1><a href='/hello01/test'>Hello,Django</a></h1>")
def test(request):
return HttpResponse('<h1><a href="/hello01">return</a></h1>')
hello01>urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('test', views.test)
]
결과화면입니다.

