天天看點

上篇python flask web服務使用MVC思想重構

檔案結構

webapp_temlate.py

templates/

├── form.html

├── home.html

└── signok.html

點選(此處)折疊或打開

  1. #!/usr/bin/env python3
  2. #-*- coding:utf-8 -*-
  3. '''
  4. from flask import Flask
  5. from flask import request
  6. from flask import render_template
  7. app = Flask(__name__)
  8. @app.route('/', methods=['GET','POST'])
  9. def home():
  10.     return render_template('home.html')
  11. @app.route('/signin',methods=['GET'])
  12. def signin_from():
  13.     return render_template('form.html')
  14. @app.route('/signin',methods=['POST'])
  15. def signin():
  16.     username=request.form['username']
  17.     password=request.form['password']
  18.     if username == 'admin' and password == 'password':
  19.         return render_template('signok.html',username=username)
  20.     return render_template('form.html', message='Bad username and password', username=username)
  21. if __name__ == '__main__':
  22.     app.run()
上篇python flask web服務使用MVC思想重構
上篇python flask web服務使用MVC思想重構
上篇python flask web服務使用MVC思想重構
上篇python flask web服務使用MVC思想重構
上篇python flask web服務使用MVC思想重構