【发布时间】:2013-02-11 08:53:51
【问题描述】:
我在配置我的 url 以显示详细视图时遇到问题。单击此链接:<a href='{% url blog_detail blog.slug %}'>{{ blog.name }}</a> 显示blog.html,而我认为它会显示blog-detail.html。没有错误,浏览器栏显示:example.com/blog/the-slug,但仍显示来自blog.html 的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'),
观看次数:
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})
编辑:@omouse 请求的输出
这是点击链接的输出。和blog.html一模一样,但应该是blog-detail.html。
<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>
【问题讨论】:
-
试试这个{{ blog.name }}
-
是的,已经尝试过了,谢谢。仍然没有运气。不知道可能是什么问题...
-
你能添加模板输出是什么吗?
-
感谢@omouse:模板输出为
blog.html。它只是虚拟文本,但我已将其包含在上面。