python - 烧瓶静态图像未加载
问题描述
所以我试图在 CSS 中将图像设置为页面的背景,但 Flask 没有正确加载图像。background.jpg
位于static/images
。
background: url("{{ url_for('static', filename='images/background.jpg') }}");
"GET /static/stylesheets/%7B%7B%20url_for('static',%20filename='images/background.jpg')%20%7D%7D HTTP/1.1" 404
我的服务器文件:
from flask import Flask, render_template, url_for
app = Flask(__name__, template_folder = "pages", static_folder="static")
@app.route("/")
def home():
return render_template("home.html")
if __name__ == "__main__":
app.run(debug=True, threaded=True, port=80)
解决方案
render_template("home.html") 只渲染 html 文件。只有在“<style>”标签中的 html 文件中,css 才会被渲染。如果它的外部文件烧瓶不会对它做任何事情。
推荐阅读
- python-3.x - 有没有办法在数据框中用 NaN 替换异常值?
- c# - System.NullReferenceException: System.Web.Mvc.WebViewPage
.Model.get 返回 null - google-app-engine - “错误:无法加载默认凭据。” 在 App Engine 生产环境中
- angular - Ionic 4 - 打开模式时无法在离子搜索栏上书写
- spring - Spring Boot 不支持请求方法“GET”
- api - RPS:无法导入名称 ExporterIFCUtils
- python - 我正在使用 pyQT 构建桌面应用程序需要在没有 cmd 窗口提示的情况下弹出应用程序窗口
- java - 如何在同一活动中从一种布局切换回父布局
- javascript - Javascript不同的轮播具有相同的布局/样式
- java - Spring Boot中微服务暂时不可用时如何实现恢复机制?