Flask: files in static folder can not be reached (404)
No, that's not what the documentation says:
- static_url_path – can be used to specify a different path for the static files on the web. Defaults to the name of the static_folder folder.
- static_folder – the folder with static files that should be served at static_url_path. Defaults to the 'static' folder in the root path of the application.
So, your files would be served at localhost:5000/react_app/build. Since that's probably not what you want, you should pass static_url_path
as well, with a value of something like "static", so that you can find the files at localhost:5000/static.
Just want to add an important point. Do not forget to add static_url_path='' because it removes any preceding path from the URL (i.e. the default /static).I am not seeing this in you code snippet.
For example,
app = Flask (__name__, static_url_path='', static_folder='web/static', template_folder='web/templates')
- static_url_path='' removes any preceding path from the URL (i.e. thedefault /static).
- static_folder='web/static' to serve any files foundin the folder web/static as static files.
- template_folder='web/templates' similarly, this changes the templatesfolder.