【问题标题】:How to make djangocms-admin-style logo dynamic?如何使 djangocms-admin 风格的标志动态化?
【发布时间】:2019-11-05 05:58:41
【问题描述】:
我正在使用 django-cms 管理风格。通过遵循此处提到的解决方案,我设法更改了默认的 DjangoCMS 徽标:
Django cms 3.4.1 admin dlogo
现在徽标是静态的,但我希望它是动态的,这意味着它应该从存储位置的数据库中获取图像路径。
由于这些管理页面不是通过views.py 呈现的,我无法将查询集发送给它。
谁能建议怎么做?
【问题讨论】:
标签:
python
django
django-templates
django-views
django-cms
【解决方案1】:
使用context_processors 我们可以做到这一点。
首先需要得到这个:https://github.com/divio/djangocms-admin-style/blob/master/djangocms_admin_style/templates/admin/inc/branding.html
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>