简体   繁体   English

在Django模板中为Title变量传递值

[英]Passing In Value for Title Variable in Django Template

I am dealing with the following code in a Django template: 我正在Django模板中处理以下代码:

<!-- 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". 对于Django管理网站,上面的title变量(即{{ title }} )的值默认为“登录”。 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: 您可以在模板中使用变量{{title}},然后使用视图传递内容,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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