Flask-模板渲染
生活随笔
收集整理的這篇文章主要介紹了
Flask-模板渲染
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一個(gè)簡單的示例,靜態(tài)HTML文件放在templates文件夾內(nèi).
目錄結(jié)構(gòu)
render.py
from flask import render_template from flask import Flask app = Flask(__name__)@app.route('/hello/') @app.route('/hello/<name>') #更改樣式 def hello(name):return render_template('hello.html',name=name)if __name__ == '__main__':app.run(debug=True)hello.html
<!doctype html> <html> <head> <title>Hello from Flask</title> <link rel="stylesheet" href="{{url_for('static',filename = 'color.css')}}"> </head> <body> {% if name %}<h1>Hello {{ name }}!</h1> {% else %}<h1>Hello World!</h1> {% endif %}</body> </html>總結(jié)
以上是生活随笔為你收集整理的Flask-模板渲染的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Flask-hello程序
- 下一篇: Flask-请求上下文