-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,64 @@ | ||
How to add a logo to Django admin? | ||
=========================================================== | ||
|
||
Your highers ups at UMSRA loge the admin you have created till now, but marketing wants to put the UMSRA logo on all admin pages. | ||
|
||
You need to override the default templates provided by Django. In your django settings, you code::`TEMPLATES` setting looks like this. :: | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [], | ||
'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', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
This means that Django will look for templates in a directory called :code:`templates` inside each app, but you can override that by setting a value for :code:`TEMPLATES.DIRS`. | ||
|
||
We change the code:`'DIRS': [],` to code:`'DIRS': [os.path.join(BASE_DIR, 'templates/')],`, and create the `templates` folder. If your code::`STATICFILES_DIRS` is empty set it to:: | ||
|
||
STATICFILES_DIRS = [ | ||
os.path.join(BASE_DIR, "static"), | ||
] | ||
|
||
Now copy the code::`base_site.html` from the admin app to :code:`templates\admin` folder you just created. Replace thre default text in `branding` block with:: | ||
|
||
<h1 id="site-name"> | ||
<a href="{% url 'admin:index' %}"> | ||
<img src="{% static 'umsra_logo.png' %}" height="40px" /> | ||
</a> | ||
</h1> | ||
|
||
With the changes your base_site.html will look like this:: | ||
|
||
{% extends "admin/base.html" %} | ||
|
||
{% load staticfiles %} | ||
|
||
{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %} | ||
|
||
{% block branding %} | ||
<h1 id="site-name"> | ||
<a href="{% url 'admin:index' %}"> | ||
<img src="{% static 'umsra_logo.png' %}" height="40px" /> | ||
</a> | ||
</h1> | ||
{% endblock %} | ||
|
||
{% block nav-global %}{% endblock %} | ||
|
||
And your admin will look like this | ||
|
||
.. image:: images/logo_fixed.png | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
How to override Django admin templates? | ||
=========================================================== | ||
|
||
https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% extends "admin/base.html" %} | ||
|
||
{% load staticfiles %} | ||
|
||
{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %} | ||
|
||
{% block branding %} | ||
<h1 id="site-name"> | ||
<a href="{% url 'admin:index' %}"> | ||
<img src="{% static 'umsra_logo.png' %}" height="40px" /> | ||
</a> | ||
</h1> | ||
{% endblock %} | ||
|
||
{% block nav-global %}{% endblock %} |