视图函数如下所示:
def stats(request):
"""the stats page"""
sidebarURLs = [reverse(p) for p in _sidebarPages]
sidebar = zip(_sidebarPages, sidebarURLs, _sidebarNames)
currpage = "dcstats"
return render_to_response('datacollection/dcstats.html',
locals(),
context_instance=RequestContext(request))
模板文件是这样的:
{% extends "datacollection/login_base.html" %}
{% load dc_extras %}
{% block title %} {% endblock %}
{% block include %}
{% endblock %}
{% block onload %}
onload="init();"
{% endblock %}
{% block content %}
{% endblock %}
{% block sidebar %}
<nav>
<ul>
{% for pg, url, name in sidebar %}
{% ifequal currpage pg %}
<li>{{name}}</li>
{% else %}
<li><a href="{{url}}">{{name}}</a></li>
{% endifequal %}
{% endfor %}
</ul>
</nav>
{% if user.is_staff %}
<p> {{ user.is_staff }} </p>
<nav>
<h3>Admin:</h3>
<ul>
<li><a href="{% url report %}">Weekly Report</a></li>
<li><a href="{% url weekly_papers %}">Weekly Papers</a></li>
<li><a href="{% url weekly_datasets %}">Weekly Datasets</a></li>
<li><a href="{% url admin %}">Admin</a></li>
<li><a href="{% url teams %}">Teams</a></li>
<li><a href="{% url submissions_admin %}">Paper Submissions</a></li>
<li><a href="{% url admin_help %}">Help</a></li>
</ul>
</nav>
{% endif %}
{% endblock %}
我不明白的是user
模板文件最后的变量,在视图函数中找不到stats
,如何将它传递到模板中?有人对此有想法吗?谢谢