1

I am dealing with the following code in a Django template:

<!-- Override title of base -->
{% block title %}{{ title }} | {{ site_title|default:_('Hello World') }}{% endblock %}

For the Django admin web site, the value of the title variable above (i.e. {{ title }}) defaults to "Log in". Where is this value being defined? I would like to change this value but pass it in rather than hard code it.

gtlambert
  • 11,711
  • 2
  • 30
  • 48
Foobar
  • 843
  • 1
  • 10
  • 23
  • For login/logout/password reset templates, the `title` is defined in `django.contrib.auth.views`. – xyres Feb 19 '16 at 17:01
  • How can I override this value by passing in a value for the variable instead of hard coding the value in the template? – Foobar Feb 19 '16 at 17:05
  • I think you'll need to replace those views with your own. But in that case, hard-coding the value of `title` in the templates seems like a far better and easier option. – xyres Feb 19 '16 at 18:44

1 Answers1

1

You can use the variable {{title}} in the template and use the view to pass the content, like this:

template.html
<title>{{ title }}</title>

views.py
def something(request):
    #Do something
    return render_to_response('template.html', context_instance=RequestContext(request,{'title':'Here is what you want to show as title'}))
M. Gar
  • 889
  • 4
  • 16
  • 33
  • Anyway to accomplish this by defining a constant instead of changing a view? I'd prefer not to override a view since I'm using the views in django.contrib.auth.views. – Foobar Feb 19 '16 at 17:56
  • maybe this could help you http://stackoverflow.com/questions/28091924/django-admin-change-header-django-administration-text-on-nginx – M. Gar Feb 19 '16 at 18:35