【发布时间】:2016-02-10 07:43:48
【问题描述】:
我试图将应用结果包含在基本模板中。模板显示正确,但我没有看到任何结果。当我直接打开应用程序 url (127.0.0.1/Project/config/) 时,它会显示结果。
项目/urls.py
urlpatterns = patterns('',
url(r'^$', 'Project.views.index'),
url(r'^config/', DisplayChangelog),
)
配置/views.py
from config.models import Changelog
def DisplayChangelog(request):
changes = Changelog.objects.all()
t = loader.get_template("changelog.html")
c = Context({'changes': changes})
return HttpResponse(t.render(c))
模板/base.html
...
<ul class="nav navbar-nav">
{% include "changelog.html" %}
</ul>
...
模板/changelog.html
...
{% for change in changes %}
<li class="media">
<div class="body">
{{ change.desc }}
<div class="date">{{ change.date }}</div>
</div>
</li>
{% endfor %}
...
【问题讨论】:
-
我不确定您希望看到什么。该模板在 /config/ 处使用信息呈现,这是您所期望的。它不适用于任何其他路径。
-
我想将此结果包含在基本模板中,因为我想在框中包含的任何子页面上看到此更改。
标签: python django django-templates django-views