반응형
CodingEntrepreneurs Django 강의 정리
views>
from django.http import HttpResponse
# Model View Template (MVT)
def home_page(request):
return HttpResponse("<h1>Hello World</h1>")
def about_page(request):
return HttpResponse("<h1>About Us</h1>")
def contact_page(request):
return HttpResponse("<h1>Contact Us</h1>")
urls>
"""try_django URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from .views import (
home_page,
about_page,
contact_page,
)
urlpatterns = [
path("", home_page),
path("about/", about_page),
path("contact/", contact_page),
path("admin/", admin.site.urls),
]
views를 여러개 만들어서 urls에 여러개 넣는 방법은 각각 뷰를 import 하고 url 패턴을 지정해준다.
적용 스크린샷>
반응형
'Python_WEB > Try_Django' 카테고리의 다른 글
[Django]Your First Template (0) | 2020.06.13 |
---|---|
[Django]path vs re_path vs url (0) | 2020.06.13 |
[Django]A First URL Mapping (0) | 2020.06.13 |
[Django]Define a View (0) | 2020.06.13 |
[Django]What Django Does (0) | 2020.06.12 |