[英]flask can not read static path and load Javascript files
my app structure is 我的app结构是
project/
configuration/__init__.py
core/
static
/app
/css
/img
/js/app.js
/lib/angular/angular.js
/partials
index.html
My file configuration/__init__.py
has something as 我的文件
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)
When I load the page localhost/index.html
, I see javascript error as 当我加载页面
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
Even though I know that these files are there, I guess that static_folder is not able to find these files, what am I doing wrong here 即使我知道这些文件存在,我想static_folder也无法找到这些文件,我在这里做错了什么
I fixed it by putting relative urls in index.html
我通过在
index.html
放置相对URL来修复它
configuration/_ init _.py configuration / _ init _.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 的index.html
<script src="../app/lib/angular/angular.js"></script>
<script src="../app/js/app.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.