简体   繁体   中英

Passing In Value for Title Variable in Django Template

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 (ie {{ 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.

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'}))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM