如何正确连接到CSS?

时间:2019-01-10 19:43:51

标签: flask pycharm static-files

我正在使用pycharm的烧瓶来创建测试站点。我将html连接到一个css文件,结果黑屏,所以我创建了一个新的css文件。不幸的是,CSS仅与此CSS连接,而我找不到原因。我做错了什么吗?

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Register</title>
        <link rel="stylesheet" type="text/css" href="{{ url_for('static', 
filename='registration_style.css') }}">
    </head>
    <body>
        <h1>HaHa</h1>
    </body>
</html>

app.py代码:

from flask import Flask, render_template, url_for

app = Flask(__name__)


@app.route('/')
def registration():
    return render_template('registration_activity.html')


@app.route('/test')
def hello_test():
    return 'Hola!'

if __name__ == '__main__':
    app.run()

1 个答案:

答案 0 :(得分:0)

我认为您缺少CSS链接,可以将以下内容添加到模板中吗?

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

因此您的模板如下所示:

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Register</title>
        <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='registration_style.css') }}">
        <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='style1.css') }}">
    </head>
    <body>
        <h1>HaHa</h1>
    </body>
</html>