2012-02-23 153 views
2

这可能看起来像一个愚蠢的问题,但我找不到任何帮助。 你会如何在管理页面提供的每个视图上创建一个注销按钮?Django注销按钮

回答

8

使用模板继承: 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> 

我使用模板继承

建议的解决您的问题