0
私はDjangoの初心者です。ユーザーがスタッフである場合にのみリンクを表示する必要があるナビゲーションバーがあります。以下は私のナビゲーションバーですユーザーがDjangoのスタッフメンバーである場合のテンプレートへのリンクを表示
<div id="navbar" class="navbar-collapse collapse" aria-expanded="false" style="height: 1px;">
<ul class="nav navbar-nav navbar-right">
<li><a href="{% url 'pledges:preferences' %}">{% trans 'Preferences' %}</a></li>
<li><a href="{% url 'pledges:account' %}">{% trans 'My Account' %}</a></li>
{# The following link should be displayed just to staff members #}
<li><a href="{% url dashboard %}">{% trans 'Dashboard' %}</a></li>
<li><a href="{% url 'pledges:logout' %}">{% trans 'Log Out' %}</a></li>
</ul>
</div>
どのように私はこれを解決することができますか?それは同じくらい簡単です
{% if request.user.is_staff %}
<li><a href="{% url dashboard %}">{% trans 'Dashboard' %}</a></li>
{% endif %}
ありがとうございます。これは魅力的に働いています。それはまさに私が望んでいたものであり、私は文脈の中で何かを渡すことを心配していました。 – lmiguelvargasf
歓迎します:-)関連するドキュメントは次のとおりです。https://docs.djangoproject.com/en/1.10/topics/auth/default/#authentication-data-in-templates – arie