文件结构
webapp_temlate.py
templates/
├── form.html
├── home.html
└── signok.html
webapp_temlate.py
webapp_temlate.py
templates/
├── form.html
├── home.html
└── signok.html
点击(此处)折叠或打开
- #!/usr/bin/env python3
- #-*- coding:utf-8 -*-
- '''
- '''
-
- from flask import Flask
- from flask import request
- from flask import render_template
-
-
- app = Flask(__name__)
-
- @app.route('/', methods=['GET','POST'])
- def home():
- return render_template('home.html')
-
- @app.route('/signin',methods=['GET'])
- def signin_from():
- 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('signok.html',username=username)
- return render_template('form.html', message='Bad username and password', username=username)
-
- if __name__ == '__main__':
- app.run()