缩小的JS文件反应无法在烧瓶应用程序内工作

时间:2017-07-18 23:56:28

标签: reactjs flask

我正在使用Flask后端编写ReactJS应用程序。在我的templates文件夹中,我有一个index.html文件,如下所示:

<html>
<body>
    <div id="app"></div>
    <script 
src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" />
    <script src="../../app/client.min.js"></script>
</body>
</html>

client.min.js文件存在于名为app的其他目录中,我通过运行webpack生成该目录。我使用index.html方法致电render_template

from flask import Blueprint
from flask import render_template
welcome = Blueprint('welcome', __name__)
@welcome.route('/', methods=['GET'])
def index():
    return render_template('index.html')

当我运行烧瓶服务器并打开localhost:8080时,我看到正确加载了jquery脚本,但加载client.min.js文件时出错。我在网络请求标题中看到了这一点 -

Request URL:http://localhost:8080/app/client.min.js
Request Method:GET
Status Code:404 NOT FOUND
Remote Address:127.0.0.1:8080
Referrer Policy:no-referrer-when-downgrade

1 个答案:

答案 0 :(得分:2)

您无法提供模板并让模板从烧瓶中的../../加载文件,您必须在烧瓶工厂或应用程序中定义静态文件夹,然后在脚本标签中使用比如<script src="static/app/app.min.js"></script>