1.3 flask如何使用templates(html)和static(css)

腫魔沒人留言?快點下去搶頭香啊!

  1. templates(html):
    from flask import Flask, render_template
    
    app = Flask(__name__)
    
    
    @app.route('/')
    def index():
        return render_template('index.html')
    
    
    if __name__ == '__main__':
        app.run()
  2. static(css):直接寫在html檔案裡面
    <!DOCTYPE html>
    <html>
        <head>
            <title>Page Title</title>
            <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
        </head>
        <body>
    
            <h1>This is a Heading</h1>
            <p>This is a paragraph.</p>
    
        </body>
    </html>
0 0 vote
Article Rating
訂閱(Subscribe)
來自於(Notify of)
0 Comments
Inline Feedbacks
View all comments