我在view.py
中有一个ListView
类
from django.shortcuts import get_object_or_404, render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.views import generic
from entertainment.models import Entertainmentblog
class ListView(generic.ListView):
template_name = 'entertainment/index.html'
context_object_name = 'latest_article_list'
slug = None
id = None
def get_queryset(self):
return Entertainmentblog.objects.order_by('-posted')[:25]
class DetailView(generic.DetailView):
model = Entertainmentblog
template_name = 'entertainment/article.html'
我使用这个视图来显示index.html
中的文章列表。但是,我想在文章之后显示article.html
中相同的文章列表。我已经正确地使用了块,但是它不会显示任何文章,因为在ListView
中模板名称是index.html.How方法我能解决这个问题吗?你知道吗
在
urls.py
中,可以将template_name
设置为ListView
url entry router的属性。你知道吗网址.py
在
views.py
中,即使您不需要设置模板。你知道吗视图.py
使用混合液:
然后重构DetailView:
如果模板中有文章:
相关问题 更多 >
编程相关推荐