Answer the question
In order to leave comments, you need to log in
How to load Flask static on hosting?
Good afternoon. I put Flask on hosting and ran into a problem.
The project is written in React + Flask.
Everything is fine on the local server:
app = Flask(__name__, static_url_path='', static_folder='templates/static')
Answer the question
In order to leave comments, you need to log in
I think the point is that the URL of your CSS/JS files, which is specified in index.html, looks like this: http://example.org/static/css/style.css
. But on the server, the real path to the file will be: http://example.org/templates/static/css/style.css
. Of course you get a 404 error on them and you get bare HTML.
Make a static symbolic link that points to templates/static in the DocumentRoot (the site's root folder).
Or, if Apache processes statics for you, then this rule in .htaccess will help:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^static/(.*)$ templates/static/$1 [QSA,L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question