Ad

Django - Change Site_header When Using `admin/login.html` Template As A Normal Login Template

- 1 answer

I am trying to use django's admin/login.html template as my login template for normal user.

Thing is it displays "Django administration" at the top of the log in form and I would like to change this.

I know it's possible to change this with a simple admin.site.site_header = 'Log in'.

The problem is: this only works when browsing /admin/login and not /login.

Here is what my urls.conf looks like

from django.conf.urls import include, url
from django.contrib.auth import views as auth_views

from django.contrib import admin
admin.site.site_header = 'Log in'
admin.autodiscover()

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^login/$', auth_views.login, {'template_name': 'admin/login.html'},
        name='login'),
    url(r'^logout/$', auth_views.logout, {'next_page': '/'}, name='logout'),
    url(r'^', include('qa.urls', app_name='qa', namespace='qa')),
]

When browsing /login I get the Django administration title and when browsing /admin/login I get the Log in title.

Is there a way to solve this without creating my own template?

Ad

Answer

You would need to pass a context variable with the name site_header into yours urls.py but that duplicates the whole thing:

url(
    r'^login/$',
    auth_views.login,
    {
        'template_name': 'admin/login.html',
        'extra_context': {'site_header': 'Log In'},
    },
    name='login'
)

Other possibility is to create your own context processor and fill site_header with whatever you want.

Another possibility is to copy admin/base_site.html into yours templates directory and overwrite the header.

Ad
source: stackoverflow.com
Ad