我目前正在学习介绍自定义 Bootstrap 3 模板并使用它构建 Django 站点的教程。在教程中,他们建议更改以下模板片段:
<a class="navbar-brand" href="index.html">Start Bootstrap</a>
到以下片段。
<a class="navbar-brand" href="/">{{ request.site.name }}</a>
但是,当我进行此更改时,没有显示站点名称。我想知道我应该在哪里设置这个名字。如果有帮助,我正在使用 Django CMS,并且只有一个名为 example.com 的站点填充在管理的 Sites 部分。
请您参考如下方法:
遇到同样的问题,找到了this in the documentation .
If you often use this pattern:
from django.contrib.sites.models import Site def my_view(request): site = Site.objects.get_current()... there is simple way to avoid repetitions. Add django.contrib.sites.middleware.CurrentSiteMiddleware to MIDDLEWARE_CLASSES. The middleware sets the site attribute on every request object, so you can use request.site to get the current site.
