Nic*_*k B 10 django slug urlconf
我在配置我的网址时无法显示详细信息视图.点击此链接:<a href='{% url blog_detail blog.slug %}'>{{ blog.name }}</a>显示blog.html,当我认为它会显示blog-detail.html.没有错误,浏览器栏example.com/blog/the-slug显示:,但仍显示html blog.html,而不是blog-detail.html.有什么想法吗?谢谢你的想法.
网址:
url(r'^blog/', 'myapp.views.blog', name='blog'),
url(r'^blog/(?P<slug>[\w-]+)/$', 'myapp.views.blog_detail', name='blog_detail'),
Run Code Online (Sandbox Code Playgroud)
观点:
def blog(request):
blog_list = Blog.objects.all()
return render(request, 'blog.html', {'blog_list':blog_list})
def blog_detail(request, slug):
blog = get_object_or_404(Blog, slug=slug)
return render(request, 'blog-detail.html', {'blog':blog})
Run Code Online (Sandbox Code Playgroud)
编辑:@omouse请求的输出
这是点击链接的输出.它完全相同blog.html,但它应该是blog-detail.html.Argggg!
<div id='content-wrapper'>
<section>
<div class='blog-name'><h2><a href='/blog/test/'>Test</a></h2></div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a ...
<div class='blog-name'><h2><a href='/blog/second-test/'>Second Test</a></h2></div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a ...
</section>
</div>
Run Code Online (Sandbox Code Playgroud)
Rud*_*lah 28
的网址是问题,第一个将匹配一切(/blog/,/blog/test/,/blog/awdlawdjaawld),你需要的美元符号$在它结束只匹配/blog/.
url(r'^blog/$', 'myapp.views.blog', name='blog'),
url(r'^blog/(?P<slug>[\w-]+)/$', 'myapp.views.blog_detail', name='blog_detail'),
Run Code Online (Sandbox Code Playgroud)
以上应该正常工作.
| 归档时间: |
|
| 查看次数: |
27627 次 |
| 最近记录: |