from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def hello_world():
return render_template('index.html')
# return "Hello"
@app.route('/user/<username>')
def show_user_profile(username):
mydic={'key1':111,'key2':222}
return render_template('user.html',name=username,dic=mydic)
if __name__ == '__main__':
app.run(debug=True)
######################user.html#############################
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> {{name|lower}}<hr> {{dic['key1']}} {{dic['key2']}} {{'<h1>hello world</h1>'|safe}} {% if name=="zhangsan" %} 你是张三 {% else %} 你不是张三 {% endif%} {%for key,value in dic.items()%} <p>{{key}}:{{value}}</p> {%endfor%} </body> </html>