简体   繁体   English

我无法在Flask应用中使用CSS设置背景

[英]I can't set the background using CSS in my Flask app

I'm creating a web app with Flask. 我正在使用Flask创建一个Web应用程序。 I created a style.css file and was able to use it successfully to specify some table attributes. 我创建了一个style.css文件,并能够成功使用它指定一些表属性。 But when I try to use code from CSS Tricks to add a background image for my landing page, the image fails to show. 但是,当我尝试使用CSS Tricks中的代码为目标网页添加背景图片时,该图片无法显示。

CSS: CSS:

html {

    /* Source: https://css-tricks.com/perfect-full-page-background-image/ */
    background: url(static/landing_page.jpeg) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

I created a simple test.html file that uses the same CSS and it worked (the image showed up, and was scaled properly). 我创建了一个简单的test.html文件,该文件使用相同的CSS并可以正常工作(图像显示出来,并且已正确缩放)。

Using built in function url_for you can get this inside jinja html, just place this on your css style 使用内置函数url_for,您可以在jinja html中获取此代码,只需将其放在您的CSS样式中

url("{{url_for('static',filename="landing_page.jpg")}}");

In general when you refer to a static file , a common practice is to target it through url_for function. 通常,当您引用静态文件时,通常的做法是通过url_for函数将其定位。

该URL必须是url(landing_page.jpeg) ,而不是url(static/landing_page.jpeg)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我不清除缓存,为什么我的 Flask 应用程序不呈现 CSS? - Why does my Flask app not render CSS if I don't clear my cache? 为什么我不能使用 SQLAlchemy 在 flask 应用程序中创建表? - Why can't I create a table in a flask app using SQLAlchemy? Flask cli 无法导入使用 FLASK_APP 设置的应用程序 - Flask cli can't import application set with FLASK_APP 如何签入 Python 是我的 Flask 应用程序已经在后台运行 - How can I check in Python is my Flask app is already running in background 无法在css(flask模板)中应用背景图像 - Can't apply background image in css (flask template) 当我在heroku上重新部署我的flask应用程序时,为什么我最近的文章不能发表? - Why can't I keep my articles published recently when I redeploy my flask app on heroku? 如何使用 Flask-SocketIO 从我的 Flask 应用程序向 HTML 发送消息 - How can I send a message from my Flask app to HTML using Flask-SocketIO 无法在烧瓶制成的网页中设置背景图片 - Can't set background image in flask made web-page 使用 nginx 作为我的服务器并运行一个简单的 flask 应用程序。 我可以配置 nginx 来服务 flask 和非 flask 网址吗? - Using nginx as my server and running a simple flask app. Can i configure nginx to serve flask and non flask urls? 为什么我的CSS样式无法在flask应用程序上显示 - Why my CSS style won't show onthe flask app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM