如何解决Flask + Vue部署在除index.html之外的每个页面上显示404
我正在处理一个已经启动的 Flask / VueJS 项目,该项目存在一个异常问题,除 index.html 页面外,每个页面都显示404我的构建文件夹( dist )。自几周以来,我一直在寻找该错误的确切位置,但我无法弄清楚。我们将前端和后端发布在同一IP地址上,但是由于/endpoint/
,我们可以将HTTP请求与基本URL分开。
示例:
(前端) https://myip.com/index.html
(后端) https://myip.com/endpoint/users
我的文件夹结构如下:
| main.py/
| certificate.crt
| private.key
| dist/
| ---- css/
| ---- fonts/
| ---- img/
| ---- js/
| ---- index.html
| src/
| ----- routes/
| ------ web_routes.py
main.py
#!flask/bin/python
from flask import Flask
from src.routes.web_routes import web
app = Flask(__name__)
if __name__ == '__main__':
app.register_blueprint(web)
app.run(ssl_context=('certificate.crt','private.key'),debug=False,host="0.0.0.0",port=443)
src / routes / web_routes.py
from flask import jsonify,Blueprint,send_from_directory
web = Blueprint("web",__name__)
@web.route('/<path:path_str>',methods=['GET'])
def WEB_get(path_str):
return send_from_directory('dist',path_str )
奇怪的是,在浏览器中,当我转到https://myip.com/home时,它显示 404 。
但是,当我转到https://myip.com/index.html时,它会重定向到https://myip.com/home并显示我的主页。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。