带有'slug'的网址不会加载视图

时间:2014-10-26 10:50:26

标签: python django url slug

我在

上配置了网址
url(r'^tags/(?P<slug>\d+)/$', TagsDetailList.as_view(), name = 'tag_detail'),

现在如果我输入url / tags / bubble(它在tag_list中给出并且有一个相关对象) 后面应该加载TagsDetailList View?

class TagsDetailList(ListView):
    queryset = Link.objects.filter(tags__name__in=['request.slug'])
    template_name = "tags_detail_list.html"

但它没有达到视图,因为我得到Page not found Error。为什么呢?

Remote Address:127.0.0.1:8000
Request URL:http://127.0.0.1:8000/tags/bubble
Request Method:GET
Status Code:404 NOT FOUND
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4,it;q=0.2
Cache-Control:max-age=0
Connection:keep-alive
Cookie:csrftoken=yY4hznFWlnvDbvvgBFWupYsrDFse32Pe; sessionid=0zx2ot6962wpx66ovmlk0z08gd5zvxho
DNT:1
Host:127.0.0.1:8000
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)         Chrome/38.0.2125.104 Safari/537.36
Response Headersview source
Content-Type:text/html
Date:Sun, 26 Oct 2014 10:47:50 GMT
Server:WSGIServer/0.1 Python/2.7.6
Vary:Cookie
X-Frame-Options:SAMEORIGIN

没有得到它。感谢

1 个答案:

答案 0 :(得分:2)

\d仅与数字匹配。您需要\w