Modifying the URL patterns
Let’s modify the URL patterns to use the publication date and slug for the post detail URL.
Edit the urls.py
file of the blog
application and replace the line:
path('<int:id>/', views.post_detail, name='post_detail'),
With the lines:
path('<int:year>/<int:month>/<int:day>/<slug:post>/',
views.post_detail,
name='post_detail'),
The urls.py
file should now look like this:
from django.urls import path
from . import views
app_name = 'blog'
urlpatterns = [
# Post views
path('', views.post_list, name='post_list'),
path('<int:year>/<int:month>/<int:day>/<slug:post>/',
views.post_detail,
name='post_detail'),
]
The URL pattern for the post_detail
view takes the following arguments:
year
: Requires an integermonth
: Requires...