Django url pattern - string parameter

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

    for having a string parameter in url you can have: url like this:

    url(r'^polls/(?P[\w\-]+)/$','polls.views.detail')
    

    This will even allow the slug strings to pass eg:strings like node-js etc.

提交回复
热议问题