article.html
正在显示,{% block homeblock %}
但所有
{{entertainment.'suffix'}}
东西{% block articlecontent %}
不在
我无法理解为什么它在所有其他块中都不能正常工作在这个块中
这是我的 views.py
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 LatestArticleMixin(object):
def get_context_data(self, **kwargs):
context = super(LatestArticleMixin, self).get_context_data(**kwargs)
try:
context['latest_article_list'] = Entertainmentblog.objects.order_by('-posted')[:25]
except:
pass
return context
class DetailView(LatestArticleMixin, generic.DetailView):
model = Entertainmentblog
template_name = 'entertainment/article.html'
这是我的模板 article.html
{% extends "articlebase.html" %}
{% block articlecontent %}
{% if error_message %}<p><strong>{{ error_message }}</strong></p>
{% else %}
<div id="art-title">
<h1 class="art-title-main">{{ entertainment.title1 }}</h1>
</div>
<div class="date_time_header"><p>{{entertainment.posted}}<p></div>
<div class="articleBody" ><img src="/static/images/rf.jpg" alt="RF" >
<div class="article-text">
{{ entertainment.body}}
{% endif %}
</div>
</div>
{% endblock %}
{% block homeblock %}
{% include "entertainment/article-index.html" %}
{% endblock %}
这是articlebase.html
文件
<html lang="en">
<head></head>
<body>
{% block articlecontent %}{% endblock %}
<div class="articles">
<div class="container-more">
<h2 class="title">More</h2>
</div>
{% block homeblock %}{% endblock %}
</div>
</body>
</html>
我的问题是article.html
显示,{% block homeblock %}
但所有
{{entertainment.'suffix'}}
东西{% block articlecontent %}
不在
由于img
标签的缘故,正在显示图像,但本文的其余部分
不是。有帮助吗?
我认为您没有传递entertainment
上下文。DetailViewobject
用作模板中对象的名称。请使用object
而不是entertainment
in模板中的in模板或将context_object_name
DetailView类上的属性设置为值“娱乐”。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句