Django url pattern - string parameter

前端 未结 6 577
面向向阳花
面向向阳花 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:47

    From Django 2.0 onward, path has been introduced. path does not take reg ex in urls, hence it is meant to be a simplified version of the older url

    From 2.0 onward you can use path instead like below :

    path('polls/', views.polls_detail)
    

    string path parameters need not be explicitly specified, as default data type for path parameters is string itself.

    Ref : https://docs.djangoproject.com/en/2.0/releases/2.0/#whats-new-2-0

提交回复
热议问题