1

I plugged Django-jet into my project and it works fine. I am trying to install a logo on the top left corner of my Django-admin, but it failed. I think the following answer is relevant here: Custom logo in django jet.

(venv) ┌─╼ [~/Projects/Work_Projects/clients.voila6.com/v6]
└────╼ ls ..
dev_requirements.pip  dploy.yml  v6_project  media      requirements.pip
dploy                 v6        manage.py    README.md  scripts
(venv) ┌─╼ [~/Projects/Work_Projects/clients.voila6.com/v6]
└────╼ ls
admin.py  clientspace     core       fixtures     messaging  __pycache__  templates  urls.py
apps.py   configurations  customers  __init__.py  orders     settings.py  tests.py   views.py

So templates/admin/base_site.html is in ~/Projects/Work_Projects/clients.voila6.com/v6, media/my_logo.png is in ~/Projects/Work_Projects/clients.voila6.com and MEDIA_URL is in ~/Projects/Work_Projects/clients.voila6.com/v6_project/conf/settings/common.py

Here is my base_site.html file

{# Template: your_app/templates/admin/base_site.html #}
{% load static i18n %}

{# Setup favicon #}
{% block extrahead %}<link rel="shortcut icon" type="image/png" href="{{MEDIA_URL}}v6_favicon.png"/>{% endblock %}

{# Setup browser tab label #}
{% block title %}{{ title }} |  {% trans "Your title" %}{% endblock %}

{# Setup branding #}
{% block branding %}
    <h1 id="site-name">
        <a href="{% url 'admin:index' %}">
            {# Your logo here #}
            <img style="background-color: white" src="{{MEDIA_URL}}{% trans "v6_logo_eng-300x150" %}.png" alt="voila6" height="50%" width="50%">
            <!--<br><br>-->
            <!--</span> {# trans "Your Branding" #%}-->
        </a>
    </h1>
{% endblock %}

I have not a lot of experience with Django and I think I forgot a step, but I can't say which one of them. How could I display my logo on my Django-admin? Knowing that Django-jet works fine.

Tell me if you need some specific details.

dave
  • 93
  • 2
  • 10
  • Just out of curiosity, why do you want to have your logo there? Usually you use `django-admin` only internally (ie. yourself/admin staff) and so it's important that the admin works as expected and is easy to navigate. You probably shouldn't use admin as a regular front-end for user input. – emihir0 Jan 04 '18 at 16:16
  • In fact, the client asks me to put the logo in the top left corner. All the staff will use the admin to make little modifications. I know it is unusual, but it is not my app. It belongs to the client. – dave Jan 04 '18 at 16:20
  • Gotcha, well I'm not familiar with `django-jet`, but this should work: in your `templates` directory (ie. `projectroot/templates`), create a `base_site.html` in path: `projectroot/templates/admin/base_site.html`), then use `extends` to extend the original `base_site.html` (at this point it just loads the original template). Now you can adjust blocks, e.g. `{% block branding %} ... {% endblock %}` to override it. Lastly, your logo and favicon should not be in `MEDIA` but in `STATIC` and you should refer to them in your templates by using `{% static ... %}` (instead of hardcoded path). – emihir0 Jan 04 '18 at 16:25
  • How do I know what is the 'projectroot'? – dave Jan 04 '18 at 16:27
  • `v6` is your project it seems like and so the template should be at `v6/templates/admin/base_site.html`. You can always install `django-debug-toolbar` to see what templates are used to render a view (among other things). – emihir0 Jan 04 '18 at 16:29
  • Yes, this is right! Yes, I installed it, but I can't see django-debug-toolbar in my admin. Is it normal? Btw, you should create a full answer in such a way I can accept it if I succeed to fix my problem. – dave Jan 04 '18 at 16:30
  • Please follow the instructions on how to enable the toolbar, it's rather straightforward (https://django-debug-toolbar.readthedocs.io/en/stable/installation.html). Make sure you use this only in dev and not in production though. (I don't have time to make a full answer right now, I might later) – emihir0 Jan 04 '18 at 16:38

0 Answers0