Django url pattern - string parameter

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

    In newer versions of Django such as 2.1 you can use

    path('polls/', views.polls_detail)
    

    as given here Django URL dispatcher

    def polls_detail(request,poll_id):
    #process your request here
    

提交回复
热议问题