美文网首页
Flask 静态文件

Flask 静态文件

作者: adonisjph | 来源:发表于2017-04-13 14:17 被阅读28次

    实现加载css,使得输出的字变为蓝色

    目录结构

    目录结构.png

    hello.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
        <title>Hello from Flask</title>
    {% if name %}
      <h1>Hello {{ name }}!</h1>
    {% else %}
      <h1>Hello World!</h1>
    {% endif %}
    </head>
    <body>
    
    </body>
    </html>
    
    h1{
        color: blue;
    }
    
    from flask import Flask, render_template
    
    app = Flask(__name__)
    
    
    @app.route('/hello/')
    @app.route('/hello/<name>')
    def hello(name=None):
        return render_template('hello.html', name=name)
    
    
    if __name__ == '__main__':
        app.run(debug=True)
    

    相关文章

      网友评论

          本文标题:Flask 静态文件

          本文链接:https://www.haomeiwen.com/subject/laybattx.html