0

I am new to django and currently I am making the tutorial. It goes well but every time at some point my admin site loses ist CSS styling and starts looking like this: enter image description here

This problem is apparently not new, as I found few posts here (e.g., this one or this one) on the topic. Following the answers I made the next steps:

  1. Running python manage.py collectstatic
  2. Modifying settings.py:

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

  3. Adding the following lines to manage.py:

    import mimetypes mimetypes.init() mimetypes.types_map['.css'] = 'text/css'

  4. Going sure that 'django.contrib.staticfiles' in settings.py is uncommented.

Nevertheless, nothing worked and my admin site still does not have CSS styling.

Note that in my case the problem is not consistent. Whenever I start a new project, the admin page is fine. The problem appears only after certain (and each time different) step throughout the tutorial. For example, last time it was after I modified the DATABASES entry in settings.py (though I went through this step smoothly one attempt before; changing the entry to its original value did not help to restore the admin page styling).

I am using django 1.9.6 with python 3.4.3 under Ubuntu 14.04.

EDIT:

I am running server with #DEBUG = True and ALLOWED_HOSTS = ['*']

Community
  • 1
  • 1
Roman
  • 2,225
  • 5
  • 26
  • 55

1 Answers1

3

Django does not serve any static or media files when DEBUG = False.

Changing the variable to True and the static files for the admin site will appear. Otherwise, you will have to use a web server program to server the admin files as well as any other static/media files included in your project.

techydesigner
  • 1,681
  • 2
  • 19
  • 28
  • Lots of similar questions about this on SO, but this was the only one that helped me - thanks! – Bill Feb 06 '20 at 21:05