django admin site nav sidebar messed up

Question:

I recently added a package to my project and did a pip freeze > requirements.txt afterwards. I then did pip install -r requirements.txt to my local and it added a sidebar.

enter image description here

I did a pip install -r requirements.txt to the server as well and it produced a different result. It’s sidebar was messed up.

enter image description here

I tried removing the sidebar by doing this answer but it did not get removed.

.toggle-nav-sidebar {
    z-index: 20;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 23px;
    width: 23px;
    border: 0;
    border-right: 1px solid var(--hairline-color);
    background-color: var(--body-bg);
    cursor: pointer;
    font-size: 20px;
    color: var(--link-fg);
    padding: 0;
    display: none; /*added*/
}

#nav-sidebar {
    z-index: 15;
    flex: 0 0 275px;
    left: -276px;
    margin-left: -276px;
    border-top: 1px solid transparent;
    border-right: 1px solid var(--hairline-color);
    background-color: var(--body-bg);
    overflow: auto;
    display: none; /*added*/
}

What should I do to fix this?

If there are any other things I can add to help, do ask.

ADD requirements.txt:

asgiref==3.3.4
certifi==2020.12.5
chardet==4.0.0
defusedxml==0.7.1
diff-match-patch==20200713
Django==3.2.3
django-cors-headers==3.7.0
django-filter==2.4.0
django-import-export==2.5.0
django-property-filter==1.1.0
djangorestframework==3.12.4
et-xmlfile==1.0.1
idna==2.10
MarkupPy==1.14
odfpy==1.4.1
openpyxl==3.0.7
python-decouple==3.4
pytz==2019.2
PyYAML==5.4.1
requests==2.25.1
sqlparse==0.3.0
tablib==3.0.0
urllib3==1.26.4
xlrd==2.0.1
xlwt==1.3.0

ADD sample github repo:

Asked By: Prosy Arceno

||

Answers:

First of all, this navbar is added by Django 3.1+ and not by any other 3rd part packages.

Copy & Pasting from Django 3.X admin showing all models in a new navbar,

From the release
notes
,

The admin now has a sidebar on larger screens for easier navigation.
It is enabled by default but can be disabled by using a custom
AdminSite and setting AdminSite.enable_nav_sidebar
to False.

So, this is a feature that added in Django 3.1 and can be removed by settings AdminSite.enable_nav_sidebar = False (see How to customize AdminSite class)


How to fix irregular styling?

You don’t have to edit any CSS or HTML file to fix the styling, because Django comes with a new set of CSS and HTML, which usually fix the issue. (That is, it is not recommended to alter the styling file only for this)

If that doesn’t work for you, it might be because of your browser cache.

If you are using Chrome,

  1. Go to the admin page
  2. Ctrl + Shift + i and select Network tab and then tick Disable Cache
  3. Refresh the page
    enter image description here
Answered By: JPG

see this side bar is added by django 3.1 and it is removable

to remove this you have to add below code in admin.py or urls.py as you are working with admin you should add below code in admin site

from django.contrib import admin

admin.autodiscover()
admin.site.enable_nav_sidebar = False

autodiscocer(): This function attempts to import an admin module in each installed application

please let me know if worked

Answered By: Vishal Pandey

I fixed this by deleting my static directory, then doing a collect static, then forcing my browser to reload.

This had been caused in a Django 3 to 4 upgrade.

Answered By: JamieO
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.