如何使 djangocms-admin-style 徽标动态化?
How to make djangocms-admin-style logo dynamic?
我正在使用 django-cms 管理风格。我按照此处提到的解决方案设法更改了默认的 DjangoCMS 徽标:
Django cms 3.4.1 admin dlogo
现在徽标是静态的,但我希望它是动态的,这意味着它应该从存储位置的数据库中获取图像路径。
由于这些管理页面未通过 views.py 呈现,我无法将查询集发送给它。
谁能建议怎么做?
使用 context_processors
我们可以做到这一点。
branding.html 文件必须放在 admin/inc 文件夹下的 templates 文件夹中,因此结构将是像这样 templates/admin/inc/branding.html
现在假设通过 context_processor 我们得到了 company_logo
,其中包含来自数据库的徽标 url。
然后在 branding.html <div id="header-logo">
会像:
<div id="header-logo">
{% if company_logo %}
<a href="/"><img src="{{ company_logo.url }}" style="height:inherit;"></a>
{% else %}
<a class="icon-logo" href="/"><span>django CMS</span></a>
{% endif %}
</div>
我正在使用 django-cms 管理风格。我按照此处提到的解决方案设法更改了默认的 DjangoCMS 徽标: Django cms 3.4.1 admin dlogo
现在徽标是静态的,但我希望它是动态的,这意味着它应该从存储位置的数据库中获取图像路径。
由于这些管理页面未通过 views.py 呈现,我无法将查询集发送给它。
谁能建议怎么做?
使用 context_processors
我们可以做到这一点。
branding.html 文件必须放在 admin/inc 文件夹下的 templates 文件夹中,因此结构将是像这样 templates/admin/inc/branding.html
现在假设通过 context_processor 我们得到了 company_logo
,其中包含来自数据库的徽标 url。
然后在 branding.html <div id="header-logo">
会像:
<div id="header-logo">
{% if company_logo %}
<a href="/"><img src="{{ company_logo.url }}" style="height:inherit;"></a>
{% else %}
<a class="icon-logo" href="/"><span>django CMS</span></a>
{% endif %}
</div>