Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的css和html文件有一些问题_Html_Css - Fatal编程技术网

我的css和html文件有一些问题

我的css和html文件有一些问题,html,css,Html,Css,这是我的html代码: <html> <head> <style rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}"></style> </head> <body> <h2 align="centre"&g

这是我的html代码:

<html>
<head>

<style rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}"></style>

</head>



<body>

   <h2 align="centre">Hello!</h2>
   <h1>Hello Again!</h1>

   <p>this is a paragraph!</p>
</body>
</html>
这是python代码:


from flask import Flask
from flask import render_template
from flask import request


app = Flask(__name__)


@app.route('/')
@app.route('/home')
def home():
    return render_template("base.html")

if __name__ == "__main__":
    app.run(debug=True)

只有一个url,但仍然不起作用 我不是html或css“专家”,所以我需要 一些帮助,我没有任何朋友,所以stackoverflow是唯一的选择

我还看到许多人使用
标记而不是
idk来区分差异
而谷歌正在展示其他东西,任何帮助都将被感谢

我不懂python,但既然可以这样使用'src',为什么还要尝试使用'href'标记获取css文件

<head>
    <style rel="stylesheet" type="text/css" src="yourfile.css"></style>
</head>


其中src可以是文件的绝对路径(“c:/yourproject/yourfile.css”)或者更好的相对路径,因此如果html和css位于同一路径中,您只需使用css文件名即可?

要包含外部样式表,您可以使用
其中styles.css是样式表的名称。这应该出现在
标记中。
标记可用于内部样式,例如:

<style>
    body {
        background: #fafafa;
        color: red;
    }
    header {
        color: blue
    }
</style>

身体{
背景:#fafafa;
颜色:红色;
}
标题{
颜色:蓝色
}

在你的HTML中。有一个页面解释了包含CSS的不同方式。

在这里,我对文件之间的链接进行了排序


这是必需的

这是main.css

这是base.html


确切的问题是什么?也许问题出在文件结构上。您没有在HTML中使用任何标题标记,这就是为什么不显示蓝色!!
flask
的方式不同于普通的
html
css
,在这种情况下,
flask
是管理
html
和其他文件的服务器。因此需要通过
使用
href
,谢谢您让我知道
<style>
    body {
        background: #fafafa;
        color: red;
    }
    header {
        color: blue
    }
</style>
body {
  background: #fafafa;
  color: red;
}

header {
  color: blue;
}
<html>
<head>
  <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}"></link>
</head>

<body>
  <h2 style="text-align: center;">Hello!</h2>
  <h1>Hello Again!</h1>
  <p>this is a paragraph!</p>
</body>

</html>
from flask import Flask
from flask import render_template
# from flask import request


app = Flask(__name__, static_url_path='/static')


@app.route('/')
# @app.route('/home')
def home():
    return render_template("base.html")


if __name__ == "__main__":
    app.run(debug=True)