简体   繁体   中英

Having trouble writing a url pattern in django

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.view.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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM