Whats the correct way to use and refer to a slugfield in a django 1.3

后端 未结 4 882
日久生厌
日久生厌 2021-02-04 22:33

Whats the correct way to use and refer to a slugfield in a django 1.3

for example the following code should link via slug to a generic view however the NoReverseMatch er

4条回答
  •  遥遥无期
    2021-02-04 22:41

    A slug value can contain any a-z, A-Z, 0-9, _ and -. The first 3 are represented by the special character w and since - itself is a special character, we need to use represent them both using a backslash \. So the correct expression becomes

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

    At least this is what is working in my case.

提交回复
热议问题