Django url parameter alias writing

created at 07-17-2021 views: 1

Django url parameter alias writing use url

from django.conf.urls import url
url(r'^date/(?P<year>\d+)/(?P<month>\d+).html', ArticleMonthArchiveView.as_view(), name='date_index'),

There are two parameters: year and month

Path parameter alias writing

from django.urls import path

# Example: /2012/08/
path('<int:year>/<int:month>/',ArticleMonthArchiveView.as_view(month_format='%m'),name="archive_month_numeric"),

# Example: /2012/aug/
path('<int:year>/<str:month>/',ArticleMonthArchiveView.as_view(),name="archive_month"),
Please log in to leave a comment.