Forums

Static file issue when deploying an Django app

I understand there are some existing problems/answers about loading static files in production.

However, my case is somehow different. My Django app not is deployed as the main app of my website (not in the public_html folder in the server), but an additional kroger fuel points app (in a folder outside public_html). The server folder directory is like this

home/myaccount/
├── public_html
|      └── static (not exist, location 1)
├── mydjango
       └── static (generated by collectstatic, location 2)
            └── css, fonts etc.

In my settings.py, STATIC_ROOT = os.path.join(BASE_DIR, 'static/') and STATIC_URL = '/static/'.

Currently, the browser will look for static files in the non-existing location 1, i.e., www.mypage.com/static/..., instead of location 2. 404 errors return.

My question is that how I can change STATIC_ROOT and STATIC_URL or other settings to make the browser look for location 2 instead of location 1?

Take a look at our help pages about static files mappings: https://help.pythonanywhere.com/pages/StaticFiles/ , https://help.pythonanywhere.com/pages/DjangoStaticFiles and https://help.pythonanywhere.com/pages/DebuggingStaticFiles