-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuse_MVC.py
39 lines (26 loc) · 921 Bytes
/
use_MVC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/env python3
# -*- coding:utf-8 -*-
# 使用MCV分离python代码和html代码
# ender_template()函数来实现模板的渲染
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 signin():
username = request.form['username']
password = request.form['password']
if username == 'admin' and password == 'password':
return render_template('signin-ok.html', username=username)
return render_template('form.html', message='Bad username or password', username=username)
if __name__ == '__main__':
app.run()
# ender_template()函数来实现模板的渲染
# use model method
# Jinja2模板
# {{name}} 变量
# {% %} 地址