我正在尝试运行Flask应用(app.py
)并加载使用动态生成的React index.html
的{{1}},但似乎后者由于某种原因无法找到。这是我在浏览器控制台中收到的错误:
bundle.js
这是我正在使用的项目树结构:
. |-- __init__.py |-- static | |-- dist | | `-- bundle.js | |-- index.html | |-- node_modules | |-- package.json | |-- package-lock.json | |-- src | | |-- App.css | | |-- App.js | | |-- components | | | |-- SearchBar.js | | | `-- Table.js | | |-- index.css | | `-- index.js | `-- webpack.config.js `-- app.py
GET http://127.0.0.1:5000/bundle.js 404 (NOT FOUND)
的内容:
index.html
最后<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<title>WebTitan</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<script type="text/javascript" src="dist/bundle.js" charset="utf-8"></script>
</body>
</html>
:
app.py
我使用以下命令生成from flask import Flask, render_template
app = Flask(__name__, static_folder='static/dist', template_folder='static')
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run()
:
bundle.js
我有什么遗失的吗?