如何在Django模板中获取网站名称? [英] How to get site name in django template?

查看:102
本文介绍了如何在Django模板中获取网站名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在管理界面中,我可以看到如何指定站点名称。但是我找不到如何在模板中使用它的文档。

In the admin interface, I can see how I can specify the name of the site. But I can't find the documentation for how to use it in my templates.

推荐答案

我遇到了类似的问题,发现这篇文章中回答的解决方案:如何在Django模板中显示站点的用户友好名称?

I faced a similar problem and found the solution answered in this post: How to display the site's user friendly name in a template in Django?

基本上,在我的settings.py中,我必须添加'django.core.context_processors.request',到我的模板->选项-> context_processors。然后,您可以使用 {{request.site.name}} 访问模板中的站点名称。

Basically, in my settings.py, I had to add 'django.core.context_processors.request', to my TEMPLATES -> OPTTIONS -> context_processors. Then you can access the site name in the template with {{ request.site.name }}.

这篇关于如何在Django模板中获取网站名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆