Here, we will explain the settings related to the URL of django.
First, edit ʻurls.py` under the project directory as follows.
Project name/urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('Application name.urls')),
]
Where it says ʻadmin /, it shows the URL to the administration screen. For other pages, ʻinclude
is used to mean that it is described in ʻurls.py` under the application directory.
Also create ʻurls.pyunder the application directory. Basically, describe the
path function in the form of
path (URL, view function (or class), name = name when back-referencing) `.
Application name/urls.py
from django.urls import path
from . import views
app_name =Application name
urlpatterns = [
path('list/', views.SampleList.as_view(), name='app_list'),
path('create/', views.SampleCreate.as_view(), name='app_create'),
path('detail/<int:pk>', views.SampleDetail.as_view(), name='app_detail'),
path('update/<int:pk>', views.SampleUpdate.as_view(), name='app_update'),
path('delete/<int:pk>', views.SampleDelete.as_view(), name='app_delete'),
]
If you want to specify view in the class, write the ʻas_view` method after the class name.
Application name/urls.py
from django.urls import path
from . import views
app_name =Application name
urlpatterns = [
path('list/', views.list_func, name='app_list'),
path('create/', views.create_func, name='app_create'),
path('detail/<int:pk>', views.detail_func, name='app_detail'),
path('update/<int:pk>', views.update_func, name='app_update'),
path('delete/<int:pk>', views.delete_func, name='app_delete'),
]
Here, I explained the URL related settings of django. Next time, I'll cover templates.
Recommended Posts