编辑Django管理员登出范本吗? [英] Edit Django admin logout template?

查看:37
本文介绍了编辑Django管理员登出范本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对Django admin注销页面做一个非常小更改.

I want to make a very small change to the Django admin logout page.

我知道如何使用模板来覆盖Django管理模板,因此我尝试对注销文件执行相同的操作.

I know how to use templates to override the Django admin templates, so I have tried to do the same thing with the logout file.

我已经在 templates/registration/logged_out.html 处设置了一个新模板.该文件的内容如下:

I have set up a new template at templates/registration/logged_out.html. The content of this file is as follows:

{% extends "registration/logged_out.html" %}
{% block content %}
<p>Thanks for using the site.</p>
<p><a href="../">Log in again</a></p>
<p><a href="/">Return to the home page</a></p>
{% endblock %}

但是,肯定有问题,因为当我尝试注销admin时,该站点停止运行.

However, something is definitely wrong, because when I try to log out of admin, the site stops running.

我找到了 Django文档页建议使用AdminSite来更改基本模板和注销页面,但这真的需要这么小的更改吗?

I've found the Django docs page recommending the use of AdminSite for changes to the base template and logout pages, but is this really necessary for such a tiny change?

如果是这样,是否有人举例说明我如何设置注销模板?我对AdminSite的说明感到很害怕.

If so, does anyone have an example of how I might set up the logout template? I'm rather intimidated by the instructions for AdminSite.

谢谢.

推荐答案

manage.py runserver终止的原因是一个继承循环.

The reason of manage.py runserver termination is an inheritance loop.

Django会加载"registration/logged_out.html",并尝试加载其父项:"registration/logged_out.html".不幸的是,parent是同一个模板,因此我们最终进入了模板继承循环.Manage.py将终止,并带有某种堆栈溢出错误...

Django loads "registration/logged_out.html" and that it tries to load it's parent: "registration/logged_out.html". Unfortunately parent is the same template and so we end up on the template inheritance loop. Manage.py will terminate with some variant of stack overflow error...

您可以通过扩展原始"registration/logged_out.html"->"admin/base_site.html"的父项来轻松解决此问题.即:

You can easily escape the issue by extending the parent of original "registration/logged_out.html" -> "admin/base_site.html". I.e:

{% extends "admin/base_site.html" %}
{% load i18n %}

{% block breadcrumbs %}<div class="breadcrumbs"><a href="../">{% trans 'Home' %}</a></div>{% endblock %}

{% block content %}
<p>Thanks for using the site.</p>
<p><a href="../">Log in again</a></p>
<p><a href="/">Return to the home page</a></p>
{% endblock %}

这篇关于编辑Django管理员登出范本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆