开发者

Having trouble writing a url pattern in django

开发者 https://www.devze.com 2023-01-27 20:09 出处:网络
I want to match the following url pattern /posts/tagged/tag-name/ I\'ve tried a few different patterns but Django splits out a 404 because it the url doesn\'t match any patterns.

I want to match the following url pattern /posts/tagged/tag-name/

I've tried a few different patterns but Django splits out a 404 because it the url doesn't match any patterns.

This is the pattern I pulled from the docs http://www.webmonkey.com/2010/02/use_url_patterns_and_views_in_django/

(r'^posts/tagged/(?P[-w]+)/$', 'blog.vie开发者_开发百科w.posts_by_tag')

Can anyone one help me out?


Try this:

(r'^posts/tagged/(?P<tag>[-\w]+)/$', 'blog.view.posts_by_tag')

Your posts_by_tag view will then receive a keyword argument called tag.

0

精彩评论

暂无评论...
验证码 换一张
取 消