Django url pattern - string parameter

前端 未结 6 575
面向向阳花
面向向阳花 2021-02-06 21:10

Django url pattern that have a number parameter is:

url(r\'^polls/(?P\\d+)/$\', \'polls.views.detail\')

What will be the correct

6条回答
  •  情深已故
    2021-02-06 21:34

    If you are using Django version >= 2.0, then this is done simply like below.

    from django.urls import path    
    
    urlpatterns = [
        ...
        path('polls//$','polls.views.detail')
        ...
    ]
    

    Source: https://docs.djangoproject.com/en/2.0/ref/urls/#django.urls.path

提交回复
热议问题