I used cPanel and deployed a Django application on my server using passenger_wsgi.py
. The problem is when I’m trying to access static files (like admin CSS file: static/admin/css/base.css
) I’m facing with 404 error.
I’ve already done collectstatic
and added PassengerPathInfoFix
method to passenger_wsgi.py
file but the output log is
Not Found: /home/mysite/public_html/build/static/admin/css/base.css
even though the outputted path exists and I can edit it using vim
.
My settings.py
:
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = "/static/"
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Any help would be appreciated.
4
Answers
Thanks to Ali's answer, For anyone with the same problem, here are the steps I've done. Wish it would be helpful:
settings.py
file contains these lines:run
python manage.py collectstatic
Edit your
passenger_wsgi.py
and add these lines:public_html
and not in thepublic_html
directory (as mine), copy thestatic
folder topublic_html
or create symbolic link usingln -s public_html/static/ public_html/subfolder/static/
(The point is thestatic
files only load from your domain/subdomain base directory) (maybe there is a better solution but this solved my problem)So I moved the project to the base directory of my domain and it worked.
Add this into url.py
Hope this help!
You can try to change STATIC_URL to STATICFILES_DIRS, this work with me!
install whitenoise and that’s it !
pip install whitenoise
settings.py :