Load static files in Django Admin panel using Python in CPanel
Asked Answered
C

2

3

I have already set up a Django Python application in my server with CPanel. The wsgi is correctly configured, the index.html (which doesn't have any css) runs properly but the admin panel doesn't load correctly the css.

I have been reading that I need to properly set the static files routes and none of this seems to work.

My settings.py file have the static directive in the installed apps and this lines at the end, where my static files of the python virtualenv is.

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static') #after collect static is run all the static files will be put in this folder
STATICFILES_DIRS = (['/home/djangouser/virtualenv/api/3.5/lib/python3.5/site-packages/django/contrib/admin/static/admin/'])

I have tried restaring the application but none of this work and my admin page still loading without css.

My index.html doesn't have any css so I don't know if this is only a problem of the admin... But I need to fix this up.

Thank you.

Cookstove answered 6/2, 2020 at 14:15 Comment(0)
I
2

The perfect solution is to serve static files via a webserver. But you can also do it with Python using Cling:

$ pip install dj-static static3

And update your wsgi.py:

...
from dj_static import Cling
...
application = Cling(get_wsgi_application())
Impetuosity answered 26/3, 2020 at 19:20 Comment(0)
M
0

I had this problem I have a cpanel host with a python application and installed django on that and in mysite.com/admin I had error for this: refused to apply style from...

this error is because I made an application on root of file manage . I mean home/my_app and I expected website look for css and js files at my_app folder which is wrong. Just move your static folder on host public_html folder ,I mean home/public_html and it works. I hope I could help you friend...

Melar answered 12/9, 2022 at 17:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.