Can I add a logo image with the new site_header parameter in Django 1.7?
I put this line in my urls.py site:
admin.site.site_header = 'My Site <img src="/static/LOGO.jpg" alt="logo" style="width:10%">'
The img tag is displayed on the page. What I'm assuming means the string is HTML escaped.
Is there a command or parameter to work with the img tag?
It would be disappointing if you still have to edit your template files to accomplish this.
Thanks in advance!
+3
source to share
1 answer
People looking for a solution can try this. I tried this in Django version 1.8 above.
Override template admin base_site.html
{% extends "admin/base.html" %}
{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}
{% block branding %}
<a href="{% url 'admin:index' %}"><img src="{{site_header}}"/></a>
{% endblock %}
{% block nav-global %}{% endblock %}
Save base_site.html in templates-> admin folder if don't create folder.
Update TEMPLATES parameter in settings.py file
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
# Image to put at the top of the admin index page
admin.site.site_header = '/static/img/logo.png'
0
source to share