在Flask里我不能加载javascript fi

2024-04-16 23:48:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试按照教程构建我的第一个单页应用程序,但我无法加载本地javascript文件。

我的Python代码:

from flask import Flask, current_app


app = Flask(__name__, static_folder='')

@app.route('/')
def index():
    return current_app.send_static_file('index.html')

if __name__ == "__main__":
    app.run()

我的HTML:

^{pr2}$

我的JavaScript:

var myApp = angular.module('myApp', []);

myApp.controller('IndexController', function($scope){
    $scope.message = 'binded ok';
});

文件夹结构是:

MyApp
 |-static
 | |-js
 |   |-app.js
 |-index.html
 |-server.py

一切都很好除了应用程序js这给了我:

Request URL: http://localhost:5000/static/js/app.js

Status Code: 404 NOT FOUND

编辑: 如果我直接使用浏览器打开index.html,则加载app.js。所以我认为烧瓶制造了一个问题。


Tags: 文件nameapp应用程序flaskindexhtmljs