You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Catch all endpoint for SPA from docs doesn't work with static_url_path="/" or static_url_path=""
Context
I'm using Flask to serve React SPA with client-side routing.
Flask worked perfectly, until I added images and decided to serve it from static/ folder.
Expected:
I can serve images from static/ folder.
I can reload a non-root page and Flask won't respond with 404 Not Found.
Current:
I can navigate to /path or /path1/path2 and etc. with no problems, but when I reload any non-root page the Flask gives me 404 Not Found and the catch-all route didn't trigger.
defcreate_app(config_class=Config) ->Flask:
app=Flask(__name__)
from .mainimportbpasmain_bpapp.register_blueprint(main_bp)
returnapp
./main/__init__.py
fromflaskimportBlueprintbp=Blueprint("main", __name__, static_folder="static", static_url_path="/")
from .mainimportroutes
./main/routes.py
from .mainimportbp@bp.route("/", defaults={"path": ""})@bp.route("/<path:path>")defcatch_all(path):
returnbp.send_static_file("index.html")
Error message
<!doctype html>
<html lang=en>
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
Environment:
Python version: Python 3.9.2
Flask version: Flask 2.2.5
The text was updated successfully, but these errors were encountered:
The static route is a catch-all path, it matches all paths below it. You need a prefix like /static to distinguish it if you have another top-level catch-all path.
Catch all endpoint for SPA from docs doesn't work with
static_url_path="/"
orstatic_url_path=""
Context
I'm using Flask to serve React SPA with client-side routing.
Flask worked perfectly, until I added images and decided to serve it from
static/
folder.Expected:
I can serve images from
static/
folder.I can reload a non-root page and Flask won't respond with
404 Not Found
.Current:
I can navigate to
/path
or/path1/path2
and etc. with no problems, but when I reload any non-root page the Flask gives me404 Not Found
and the catch-all route didn't trigger.Example:
folder structure
./__init__.py
./main/__init__.py
./main/routes.py
Error message
Environment:
Python 3.9.2
Flask 2.2.5
The text was updated successfully, but these errors were encountered: