【问题标题】:Background Image is not displaying in flask背景图像未显示在烧瓶中
【发布时间】:2020-01-17 18:38:23
【问题描述】:

这是我的 html 模板 homepage.html in /home/saurabh/flask/templates

<!DOCTYPE>
<html>
<head>
<title>homepage</title>
<style>
body{
        background-image:url("/home/saurabh/Pictures/599783.jpg");
        background-attachment: fixed;
    }
</style>
</head>
<body>
    <h1>Welcome to our Homepage</h1>
    <h3>We will try to make u happy <strong>YOU</strong></h3>
    <nav>
        <a href="login.html">LOGIN</a>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="signup.html">SIGNUP</a>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="about.html">ABOUT US</a>
    </nav>
</body>
</html>

这是我在/home/saurabh/flask中呈现上述模板的python脚本

from flask import Flask,render_template
app=Flask(__name__)
@app.route('/')
def home():
    return render_template("homepage.html")
if __name__=="__main__":
    app.run(debug=True)

一切正常,但背景图像。我已经尝试使用静态目录,但没有任何效果。 背景图像没有显示在网络浏览器中??

【问题讨论】:

    标签: html css python-3.x flask


    【解决方案1】:

    您需要创建一个名为:/home/saurabh/flask/static的目录

    将背景图像文件移动到该目录。

    然后将模板文件中的行更改为:

    background-image: url("{{ url_for('static', filename='599783.jpg') }}");
    

    【讨论】:

      【解决方案2】:

      您可以从网络服务器而不是烧瓶默认网络服务器为您的文件调用图像。

      http://www.yoursitename.com/images/image.jpg

      请参考Flask Documentation 解决此图像问题

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-06-28
        • 2020-02-05
        • 2019-02-11
        • 2019-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多