반응형
CodingEntrepreneurs Django 강의 정리
include>
1. URLconf모듈
2. 전체 Python 가져오기 경로를 사용하는 기능
3. URL패턴을 반환하는 항목 또는 이러한 항목과 애플리케이션 네임 스페이스의 이름을 포함
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, re_path, include # url
from blog.views import blog_post_create_view
from .views import (
home_page,
about_page,
contact_page,
example_page,
)
urlpatterns = [
path("", home_page),
path("blog-new/", blog_post_create_view),
path("blog/", include("blog.urls")),
# re_path(r"^blog/(?P<slug>\w+)/$", blog_post_detail_page),
path("page", about_page),
path("pages", about_page),
re_path(r"^pages?/$", about_page),
re_path(r"^about/$", about_page),
path("contact/", contact_page),
path("example/", example_page),
path("admin/", admin.site.urls),
]
urls(신규 생성)>
from django.contrib import admin
from django.urls import path
from blog.views import (
blog_post_detail_page,
blog_post_list_view,
blog_post_create_view,
blog_post_update_view,
blog_post_delete_view,
)
urlpatterns = [
path("", blog_post_list_view),
path("<str:slug>/", blog_post_detail_page),
path("<str:slug>/edit", blog_post_update_view),
path("<str:slug>/delete", blog_post_delete_view),
]
반응형
'Python_WEB > Try_Django' 카테고리의 다른 글
[Django]Submit Raw HTML Form (0) | 2020.06.17 |
---|---|
[Django]In App Templates (0) | 2020.06.17 |
[Django]Routing the Views (0) | 2020.06.16 |
[Django]Blog Post List View (0) | 2020.06.16 |
[Django]CRUD View Outline (0) | 2020.06.16 |