admin管理员组文章数量:1391977
my app structure is
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
# 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
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
my app structure is
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
# 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
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
Share Improve this question asked Apr 21, 2013 at 6:11 daydreamerdaydreamer 92.3k204 gold badges473 silver badges750 bronze badges1 Answer
Reset to default 5I fixed it by putting relative urls in index.html
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
<script src="../app/lib/angular/angular.js"></script>
<script src="../app/js/app.js"></script>
本文标签: pythonflask can not read static path and load Javascript filesStack Overflow
版权声明:本文标题:python - flask can not read static path and load Javascript files - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744753836a2623341.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论