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

后端 未结 4 881
日久生厌
日久生厌 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:54

    In your template, assuming post is an instance of your model:

    {% url single_post post.slug %}
    

    Your url regex should look like the following:

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

    To test the above regex, try to access a few posts directly in your browser with a variety of valid slugs and see if they works. Once this is done, start testing the url names.

提交回复
热议问题