2
這可能看起來像一個愚蠢的問題,但我找不到任何幫助。 你會如何在管理頁面提供的每個視圖上創建一個註銷按鈕?Django註銷按鈕
這可能看起來像一個愚蠢的問題,但我找不到任何幫助。 你會如何在管理頁面提供的每個視圖上創建一個註銷按鈕?Django註銷按鈕
使用模板繼承: https://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance 或包括標籤: https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#include
實例與模板繼承: 我們有我們的應用程序的所有頁面的基本模板:
# base.html #
<html>
<head>...</head>
<body>
<a href="/logout">logout</a> # or use the "url" tag: {% url logout_named_view %}
{% block content %} {% endblock %}
</body>
</html>
# other_pages.html #
{% extends "base.html" %}
{% block content %}
<div class="content">....</div>
....
....
{% endblock %}
現在,我們有從base.html繼承的所有頁面上的註銷鏈接
包含標記的示例:
# user_panel.html #
<div class="user_panel">
<a href="/logout">logout</a>
</div>
# other_pages #
<html>
<head>...</head>
<body>
{% include "user_panel.html" %}
...
...
</body>
</html>
我使用模板繼承
建議的解決您的問題