Skip to content

Commit c54bfc1

Browse files
committed
add flask app
1 parent 4ec9ad8 commit c54bfc1

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

py3/web/do_flask.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
from flask import Flask
5+
from flask import request
6+
7+
app = Flask(__name__)
8+
9+
@app.route('/', methods=['GET', 'POST'])
10+
def home():
11+
return '<h1>Home</h1>'
12+
13+
@app.route('/signin', methods=['GET'])
14+
def signin_form():
15+
return '''<form action="/signin" method="post">
16+
<p><input name="username"></p>
17+
<p><input name="password" type="password"></p>
18+
<p><button type="submit">Sign In</button></p>
19+
</form>'''
20+
21+
@app.route('/signin', methods=['POST'])
22+
def signin():
23+
# 需要从request对象读取表单内容:
24+
if request.form['username']=='admin' and request.form['password']=='password':
25+
return '<h3>Hello, admin!</h3>'
26+
return '<h3>Bad username or password.</h3>'
27+
28+
if __name__ == '__main__':
29+
app.run()

0 commit comments

Comments
 (0)