【问题标题】:URL with 'slug' doesnt load the view带有“slug”的 URL 不会加载视图
【发布时间】:2014-12-21 17:21:05
【问题描述】:

我已经配置了网址

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"

但它没有到达视图,因为我得到页面未找到错误。为什么?

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

没听懂。谢谢

【问题讨论】:

    标签: python django url slug


    【解决方案1】:

    \d 仅匹配数字。你需要\w

    【讨论】:

      猜你喜欢
      • 2018-01-10
      • 2016-01-11
      • 1970-01-01
      • 2021-11-02
      • 2016-02-24
      • 1970-01-01
      • 2012-06-12
      • 2019-04-04
      • 1970-01-01
      相关资源
      最近更新 更多