Forums

static files not automatically served

Hi,

I'm not sure if I am fully understanding how static files are served or if Python Anywhere does things in a different way that I am not aware of.

I've just started a new webapp blogapp.longuerue.com. There is nothing much in there yet, but to test things I went to the admin page and found there was no styling, so I set my STATIC_ROOT as "/home/stephenl6705/home_blogapp/static", ran collectstatic and reloaded the webapp.

But nothing changed, so I included the link on the Python Anywhere Web page and now it works.

But do I need to do this? I thought having the STATIC_ROOT path defined and all required static files in there Django should find those static files there and serve them automatically, not?

Stephen

You need to set it up once in the static files option under the webapps tab for each webapp.

The reason we do this separately is because PythonAnywhere serves your static files separately, so that those files can load faster and won't block your webapp workers etc. (ie. using django to serve your static files is really inefficient)

The purpose of running collect static is just to tell django to dump all the static files into the static directory, so that you can use something else to serve them up. Of course, django's debugging only runserver command does also serve up the static files, but you are supposed to do it separately.

Ok, I got it. Thanks for the explanation!