我需要django模板中的鏈接,如果用戶已通過身份驗證,它將變成註銷。 (我已經實現登錄/註銷頁面)如何添加登錄/註銷鏈接(Django)
嘗試{% if user.is_authenticated %} {% endif %}
和{% if user.is_anonymous %} {% endif %}
但沒有奏效。
測試代碼(https://docs.djangoproject.com/en/dev/topics/auth/) -
{% if user.is_authenticated %}
<p>Welcome, {{ user.username }}. Thanks for logging in.</p>
{% else %}
<p>Welcome, new user. Please log in.</p>
{% endif %}
返回假埃文登錄成功後。
使用'{%其他%}'爲好。 – Blender 2012-04-04 02:51:43
@Blender是的,嘗試與此同時使用。 – ChamingaD 2012-04-04 02:54:09
然後你編碼錯了。發佈您的模板代碼。 – Blender 2012-04-04 02:54:33