问题
I want to make a very small change to the Django admin logout page.
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.
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 %}
However, something is definitely wrong, because when I try to log out of admin, the site stops running.
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?
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.
Thanks.
回答1:
The reason of manage.py runserver termination is an inheritance loop.
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...
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 %}
回答2:
You're getting a template import loop. The template loader won't load the base template form wherever you've got Django installed, because it sees that you have that template in your project's template folder.
I think you'll need to copy the log out template from where you have Django installed to your project's template folder. Unfortunately that's the only way that seems to work. This method also means that if updates are made to the Django admin templates, you'll have to manually apply them to your modified templates.
来源:https://stackoverflow.com/questions/6572536/edit-django-admin-logout-template