Search code examples
pythonubuntuflaskstaticuwsgi

Flask & uwsgi not rendering files from static folder


I'm following this tutorial, everything went well but the app is not rendering files from static folder (css, images, scripts, etc).

I gave every permission to the folder (sudo chmod a+rwx static), and the sub-folders, but still not rendering.

The code i'm using is one that worked before with almost the same config (Ubuntu 18.04 back in the day)

app = Flask(__name__,static_url_path='',static_folder="static")

And my nginx config file :

 location / {
    include uwsgi_params;
    uwsgi_pass unix:/home/sydney/ecocathlon/ecocathlon.sock;
}
 location /static {
     root /home/sydney/ecocathlon/static;
 }

Do you have any ideas on how i can allow the program to access to the folder ?

Thanks in advance,

Sydney R.


Solution

  • Use alias instead of root:

    location /static {
         alias /home/sydney/ecocathlon/static;
    }
    

    Based on this answer.

    Also I'd leave static_url_path out of your application definition, and also static_folder as you're just setting this to the default:

    app = Flask(__name__)
    

    static_url_path controls how the app generates URLs to static files, so you'd be forcing it to generate links like /something.js instead of /static/something.js by setting this to an empty string.