본문 바로가기

Python_WEB/Try_Django

[Django]Routing the Views

반응형

CodingEntrepreneurs Django 강의 정리

blog_post_delete.html>

{% extends "base.html" %}

{% block content %}

<h1>{{ object.title }} - Delete</h1>
<p>{{ object.content }}</p>

{% endblock %}

 

blog_post_update.html>

{% extends "base.html" %}

{% block content %}

<h1>{{ object.title }} - Update</h1>
<p>{{ object.content }}</p>

{% endblock %}

 

blot_post_create.html>

{% extends "base.html" %}

{% block content %}

<h1>Create new blog post</h1>

{% endblock %}

 

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  # url

from blog.views import (
    blog_post_detail_page,
    blog_post_list_view,
    blog_post_create_view,
    blog_post_update_view,
    blog_post_delete_view,
)
from .views import (
    home_page,
    about_page,
    contact_page,
    example_page,
)

urlpatterns = [
    path("", home_page),
    path("blog/", blog_post_list_view),
    path("blog-new/", blog_post_create_view),
    path("blog/<str:slug>/", blog_post_detail_page),
    path("blog/<str:slug>/edit", blog_post_update_view),
    path("blog/<str:slug>/delete", blog_post_delete_view),
    # 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),
]

 

반응형

'Python_WEB > Try_Django' 카테고리의 다른 글

[Django]In App Templates  (0) 2020.06.17
[Django]Include URLs  (0) 2020.06.17
[Django]Blog Post List View  (0) 2020.06.16
[Django]CRUD View Outline  (0) 2020.06.16
[Django]CRUD & Views  (0) 2020.06.16