Warm tip: This article is reproduced from serverfault.com, please click

Flask & uwsgi not rendering files from static folder

发布于 2020-11-28 15:47:46

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.

Questioner
Sydney R
Viewed
0
v25 2020-11-29 00:52:08

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.