后台代码 MVC
from flask import Flask,request,render_template
app = Flask(__name__)
@app.route('/',methods=['GET','POST'])
def home():
return render_template('home.html')
@app.route('/signin',methods=['GET'])
def signin_form():
return render_template('form.html')
@app.route('/signin',methods=['POST'])
def sigin():
username = request.form['username']
password = request.form['password']
if username.strip() == 'admin' and password.strip() == 'password':
return render_template('signin-ok.html',username=username)
return render_template('form.html',message='Bad information...',username=username)
if __name__ == '__main__':
app.run()
View 都放到 templates 目录下
Home
Please Sign In{% if message %}
{{ message }}
{% endif %}
Please sign in:
Sign In
Welcome, {{ username }}Welcome, {{ username }}!
标签:username,__,form,render,flask,app,jinja2,template,轻量
来源: https://www.cnblogs.com/Frank99/p/10551483.html