S
S
s1vemod2021-03-18 16:13:03
Flask
s1vemod, 2021-03-18 16:13:03

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')


But when I put it on hosting (wsgi.py, .htaccess), index.html is rendered, but the rest of the css/js doesn't want to.

Tell me what could be the problem?
The structure is something like this:

app.py
templates
∟ static
---∟ css
∟ index.html


Also the html that is displayed on the page:
You need to enable JavaScript to run this app.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
ge, 2021-03-19
@s1vemod

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 question

Ask a Question

731 491 924 answers to any question