Django:user.is#u已验证,无需通过';用户';?

Django:user.is#u已验证,无需通过';用户';?,django,django-templates,Django,Django Templates,当我在学习教程时,我遇到了这样一个问题: 我有一个模板'base.html',其中我甚至没有从视图中传递'user'变量的值。 但它仍然对用户进行身份验证。我不明白这是怎么回事: base.html: {% if user.is_authenticated %} <div id='nav'> <a href='/'/> mysite </a> | <a href='/user/{{user.username}}/'>{{ user

当我在学习教程时,我遇到了这样一个问题:
我有一个模板'base.html',其中我甚至没有从视图中传递'user'变量的值。 但它仍然对用户进行身份验证。我不明白这是怎么回事:
base.html:

{% if user.is_authenticated %}

<div id='nav'>
    <a href='/'/> mysite </a> |
    <a href='/user/{{user.username}}/'>{{ user.username }} </a>(<a href='/logout'>logout</a>)
</div>

{% endif %}
<h1>{% block head %}{% endblock %}</h1>
{% block content %}{% endblock %}
{%if user.u经过身份验证%}
|
()
{%endif%}
{%block head%}{%endblock%}
{%block content%}{%endblock%}

您可能拥有将用户变量添加到上下文的auth上下文处理器和/或中间件集

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
)

MIDDLEWARE_CLASSES = (
    "django.contrib.auth.middleware.AuthenticationMiddleware",
)

您可以访问
用户
对象,即使您没有在视图响应中隐式传递它。
默认情况下,它是一个
匿名用户
,直到用户登录并对自己进行身份验证为止

中间件与此无关。@hedde没有,我没有设置上下文处理器。没有关于模板从何处获取“用户”值的线索。