2

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>

account-div では機能しますが、sidebar-div では機能しません。

助言がありますか?

4

1 に答える 1

1

あなたが持っている

 {% 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 not user.is_authenticated %} を試すことができます

于 2012-07-09T19:00:45.803 に答える