Django身份验证行为怪异。“工作”;有些时候",;,不总是

Django身份验证行为怪异。“工作”;有些时候",;,不总是,django,templates,authentication,Django,Templates,Authentication,我对Django的认证系统有点问题。我已经设置了一个登录页面、注销页面和一个基本配置文件页面。现在,我试图将站点上的不同区域限制为仅经过身份验证的用户。它适用于某些模板,而不适用于其他模板 也许最奇怪的是,它在同一个模板中工作/不工作 这是base.html: <div id="account"> {% if user.is_authenticated %} Hello, <a href="{% url accounts-profile %}">{

我对Django的认证系统有点问题。我已经设置了一个登录页面、注销页面和一个基本配置文件页面。现在,我试图将站点上的不同区域限制为仅经过身份验证的用户。它适用于某些模板,而不适用于其他模板

也许最奇怪的是,它在同一个模板中工作/不工作

这是base.html:

<div id="account">
    {% if user.is_authenticated %}
        Hello, <a href="{% url accounts-profile %}">{{ user.username }}</a>! | <a href="{% url accounts-logout %}">Log out</a>
    {% else %}
        <a href="{% url accounts-login %}">Log in</a>
        or
        <a href="#">Sign up</a>
    {% endif %}
</div>


<div id="sidebar">
    {% if user.is_authenticated %}
        <h3 id="plus" style="padding-top: 20px;"><a href="#">Sign up!</a></h3>
        <a href="{% url accounts-login %}">Log in</a>
    {% else %}
        <div style="margin-top: 45px">
            <a href="{% url accounts-profile %}">Profile</a>
        </div>
    {% endif %}     
</div>

{%if user.u经过身份验证%}
你好
{%else%}
或
{%endif%}
{%if user.u经过身份验证%}
{%else%}
{%endif%}
在account div中工作,但不在sidebar-div中工作

有什么建议吗?

你有什么建议吗

 {% if user.is_authenticated %}
        <h3 id="plus" style="padding-top: 20px;"><a href="#">Sign up!</a></h3>
        <a href="{% url accounts-login %}">Log in</a>
 {% else %}
{%if user.u经过身份验证%}
{%else%}
如果他登录了,为什么他必须注册?
您可以尝试{%if not user.is_authenticated%}

您可以发布您的视图吗?您是否也要确保
context\u instance=RequestContext(request)
request context?它是base.html-template,因此没有特定的视图?哪些视图正在加载扩展它的模板?各种不同的模板(基本上每个人)-这是站点的侧栏。太棒了。这一整天都在困扰着我。人为错误。赢我知道这种感觉,有时在工作中会让我感觉到。然后当我回家看代码的时候,我就想啊哈!