Search code examples
djangodockernginxdjango-admindjango-staticfiles

Style of django admin is not shown


This is how my Django admin page looks like:

enter image description here

Though in my network section this is the result: enter image description here

And the url path of these requests are correctly set by the static url, these are the Django settings:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

I collect statics before serving my app: RUN python3 manage.py collectstatic --noinput (This is part of my Dockerfile)

some parts of my docker-compose:

  web:
    restart: always
    image: <some private image>
    ports:
      - "127.0.0.1:8000:8000"
    volumes:
      - static_volume:/<path>/static

  nginx:
    container_name: nginx
    image: nginx:1.19.3
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - static_volume:/home/status/statics

volumes:
  static_volume:


This is inside my nginx container:

enter image description here

Also this is in my https config for my nginx:

enter image description here

Well to me it seems like everything is working and I can't understand what's wrong with it.


Solution

  • I checked the console of the browser and I found some warnings. The styles were fetched as text and the problem was the wrong Content-Type header. I add mime.types file to my container and include that in my nginx config.

    include /etc/nginx/mime.types;