我跟随本教程使用flaskhttp://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-ii-templates开发模板
我的文件树是下一个:
/static
/js
bootstrap.min.js
jquery_1.11.3.js
/css
bootstrap.min.css
/images
/templates
index.html
/python_venv
server.py
在服务器.py代码:
^{pr2}$和css链接在里面索引.html代码如下:
<script src="/static/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/static/css/bootstrap.min.css"/>
<script src="/static/js/jquery_1.11.3.js"></script>
nginx配置:
location /subdomain/{
root /apps/subdomain/static;
uwsgi_pass unix:///tmp/subdomain.sock;
include uwsgi_params;
}
当我在Chrome上检查时,索引没有加载CSS文件。我用开发人员的工具检查了网络,错误是404。 我也尝试了类似的代码,我看到这个未解决的问题,但没有成功 Inline CSS background:url() not working in Jinja2 template
有什么帮助吗?在
问题出在服务器上。在
我不得不为烧瓶提供静态文件夹模板可以加载css。在
我在nginx配置文件中写了下一个:
我不使用url_for()函数y将资源的url写成:
^{pr2}$最后结账@应用程序路径()在呈现模板的文件中是正确的,那么flask模板可以访问css、图像和js。在
如果将静态文件直接放在/static文件夹下,这应该可以工作
如果您不想这样做,请按照以下问题中的说明进行操作:
Link to Flask static files with url_for
相关问题 更多 >
编程相关推荐