0

After hosting my Django project on PythonAnywhere, the Django Admin login page looks like this: enter image description here

I have run python manage.py collectstatic and this still happens. There are many errors in the Javascript console that include:

Refused to apply style from 'example.com/static/admin/css/dark_mode.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

The other errors also reference to MIME. This is my settings.py:

STATIC_URL = "/static/"
STATICFILE_DIRS = [BASE_DIR / 'static']
STATIC_ROOT = '/home/mywebsite/surveys/static'

I also get these error in the error log:

2023-06-22 11:37:29,062: Not Found: /static/admin/css/dark_mode.css
2023-06-22 11:37:29,063: Not Found: /static/admin/css/base.css
2023-06-22 11:37:29,215: Not Found: /static/admin/css/nav_sidebar.css
2023-06-22 11:37:29,224: Not Found: /static/admin/css/login.css
2023-06-22 11:37:29,403: Not Found: /static/admin/css/responsive.css
2023-06-22 11:37:29,404: Not Found: /static/admin/js/nav_sidebar.js
2023-06-22 11:37:29,408: Not Found: /static/admin/js/theme.js

Can anyone tell me why this is happening?

2 Answers2

0

I fixed the error. I'm posting this answer for future reference. I had improperly configured my settings.py for static files. I needed to change

STATIC_URL = "/static/"
STATICFILE_DIRS = [BASE_DIR / 'static']
STATIC_ROOT = '/home/mywebsite/surveys/static'

to

STATIC_URL = "/static/"
STATICFILE_DIRS = [os.path.join(BASE_DIR, "static"),]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

And that fixed everything!

0

You need to add STATIC_ROOT instead of STATICFILES_DIRS

STATIC_URL = '/static/'

STATIC_ROOT = BASE_DIR / 'static'
# STATICFILES_DIRS = [BASE_DIR / 'static'] <---- comment this

then run the command

  • python manage.py collectstatic

then reload the app (I think it will work)