Created
January 9, 2018 08:44
-
-
Save shau-lok/3d6c15b35763a3405cfe51d5e52caf48 to your computer and use it in GitHub Desktop.
django-url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://docs.djangoproject.com/en/2.0/topics/http/urls/ | |
| # django的url正则匹配 | |
| from django.urls import path, re_path | |
| from . import views | |
| urlpatterns = [ | |
| path('articles/2003/', views.special_case_2003), | |
| re_path('articles/(?P<year>[0-9]{4})/', views.year_archive), | |
| re_path('articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/', views.month_archive), | |
| re_path('articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<slug>[\w-_]+)/', views.article_detail), | |
| ] | |
| # year是参数名 | |
| ######################################################################################### | |
| from django.urls import path | |
| from . import views | |
| urlpatterns = [ | |
| path('articles/2003/', views.special_case_2003), | |
| path('articles/<int:year>/', views.year_archive), | |
| path('articles/<int:year>/<int:month>/', views.month_archive), | |
| path('articles/<int:year>/<int:month>/<slug:slug>/', views.article_detail), | |
| ] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment