Forums

Not able load static files from STATICFILES_DIRS

Hi,

I am new to django and I managed to go through all the processes to setup my existing django project from local > github > pythonanywhere. Unfortunately, my static files that I have defined in STATICFILES_DIRS of the settings.py are not loaded in PythonAnywhere but it's working perfectly on my local machine.

I am getting error 404 for all these static files that should be displayed on the UI. The following are the static file configurations in the setting.py that I have done:

STATIC_ROOT = None

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    ('assets', '/home/wellplanforme/plantrip/WellPlanForMe/static'),
    )

I also define the path in the Web tab.

The error that I am getting is the following: GET /static/assets/images/world_1.jpg HTTP/1.1" 404 1110

Same issue for admin static: /static/admin/css/base.css HTTP/1.1" 404 1107

Any advice on solving this issue?

Regards, Szelee

Hi there -- looking at your static file setup in the "Web" tab it looks like there's an error -- the directory you've specified for /static/ doesn't exist. I think you mean /home/wellplanforme/plantrip/static instead of /home/wellplanforme/plantrip/WellPlanForMe/static

Hi Giles,

I must be too tired. Thank you. I have changed that, but still getting the error. Is there anything else that I have miss-configured? Remember I am using STATICFILES_DIRS with variable 'assets'.

GET /static/assets/images/world_1.jpg HTTP/1.1" 404 1115

Regards, szelee

Ah, right -- the assets directory isn't a subdirectory of /home/wellplanforme/plantrip/static, so you need to change the URL for your static file mapping to /static/assets and reload the web app again. It should work then.

Then for the Django admin stuff, you'll need to add a different file routing, probably from /static/admin to the appropriate part of your Django codebase -- given that you're using a virtualenv, it will probably be /home/wellplanforme/.virtualenvs/env/lib/python2.7/site-packages/django/contrib/admin/static/admin

Hi Giles,

Thank you. It's working now.

Regards, szelee

Cool, thanks for confirming!