Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are many ways to store the last visited non-admin url in request.session. For example, a middleware:</p> <pre><code>import re class LastSiteUrl(object): def is_admin_url(self, url): return re.search('^(http:\/\/.*){0,1}\/admin\/', url) is not None def process_request(self, request): if self.is_admin_url(request.path) and \ not self.is_admin_url(request.META.get('HTTP_REFERER','')): request.session['last_site_url'] = request.META.get('HTTP_REFERER','') </code></pre> <p>Then override the template:</p> <ol> <li><p><strong>Store the last non admin url in request.session</strong>, e.g. put the above class in <code>yourproject/middleware.py</code>, add to <code>settings.MIDDLEWARE_CLASSES</code>: <code>middleware.LastSiteUrl</code></p></li> <li><p><strong>Prepare the admin base site template for overriding</strong>, copy <code>django/contrib/admin/templates/admin/base_site.html</code> to <code>yourproject/templates/admin/base_site.html</code></p></li> <li><p><strong>Link to request.session.last_site_url</strong>, e.g. in <code>yourproject/templates/admin/base_site.html</code>, find <code>{% block branding %}</code>, before the H1 tag of this block, add an HTML link to <code>{{ request.session.last_site_url }}</code>.</p></li> </ol> <p>It should look like that:</p> <pre><code>{% block branding %} {% if request.session.last_site_url %} &lt;a href="{{ request.session.last_site_url }}"&gt;back to site&lt;/a&gt; {% endif %} &lt;h1 id="site-name"&gt;{% trans 'Django administration' %}&lt;/h1&gt; {% endblock %} </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload