flask jinja2 template engine

from flask import Flask, jsonify,render_template
app = Flask(__name__)

@app.route("/")
def hello():
return jsonify({"username":"hello world! Zhang"})

@app.route("/jinja2")
def jinja2():
return render_template('jinja2.html',url_str=url_str)

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

Rendering class render_template program first parameter is passed a web page, the back of the parameters are all key-value pairs, in front of the equal sign is the key variable names used in the template, the equal sign is the assignment;

Page directly with {{url_str}} This form can be a reference to the assignment server. These are jinja2 simple template engine.

Guess you like

Origin www.cnblogs.com/braveheart007/p/11144995.html