Flask:从非标准位置呈现js嵌入网页

Flask:从非标准位置呈现js嵌入网页,flask,Flask,我的烧瓶应用程序具有以下结构: app.py - templates/ - static/ - external/ external - external.html js/ img/ 在external下,我有一个js嵌入的html文件。其结构如下: app.py - templates/ - static/ - external/ external - external.html js/ img/ 当我得到一个看起来像

我的烧瓶应用程序具有以下结构:

app.py
- templates/ 
- static/
- external/
external - 
     external.html
     js/
     img/
external
下,我有一个js嵌入的html文件。其结构如下:

app.py
- templates/ 
- static/
- external/
external - 
     external.html
     js/
     img/
当我得到一个看起来像
http:///external?key1=val2&key2=val2
,我想向客户端发送
external.html
。我的代码如下所示:

@app.route("/external")
    return flask.send_from_directory(external, 'external.html')

但是,我得到了服务器异常,没有任何东西返回到客户端

这看起来像是路径问题。您可能需要手动设置文件夹的路径

app = Flask(__name__, external_folder='external')  

@app.route('/external',methods=['GET'])  
def send_file(filename): 
    return send_from_directory(app.external_folder, filename)

此外,如果这是在生产中,您应该使用标准的web服务器(如Apache)来为您的文件提供服务,这是一个输入错误。固定的。