2013-04-21 51 views
3

我的应用程序结构瓶无法读取静态路径和加载JavaScript文件

project/ 
     configuration/__init__.py 
     core/ 
     static 
      /app 
       /css 
       /img 
       /js/app.js 
       /lib/angular/angular.js 
       /partials 
      index.html 

我的文件configuration/__init__.py有什么作为

# setting up template directory 
TEMPLATE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../static/app') 

app = Flask(__name__, template_folder=TEMPLATE_DIR, static_folder=TEMPLATE_DIR) 

当我加载localhost/index.html的页面,我看到的JavaScript错误为

GET http://127.0.0.1:5000/js/app.js 404 (NOT FOUND) home:8 
GET http://127.0.0.1:5000/lib/angular/angular.js 404 (NOT FOUND) home:8 

尽管我知道这些文件在那里,但我猜static_folder无法找到这些文件,我在做什么错在这里

回答

4

我通过把相对URL在index.html

配置/ _ 初始化 _.py

# setting up template directory 
ASSETS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../static/app') 

app = Flask(__name__, template_folder=ASSETS_DIR, static_folder=ASSETS_DIR) 

固定它index.html

<script src="../app/lib/angular/angular.js"></script> 
    <script src="../app/js/app.js"></script>