且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

上篇python flask web服务使用MVC思想重构

更新时间:2022-05-06 23:44:34

文件结构
webapp_temlate.py
templates/
├── form.html
├── home.html
└── signok.html

webapp_temlate.py

点击(此处)折叠或打开

  1. #!/usr/bin/env python3
  2. #-*- coding:utf-8 -*-
  3. '''
  4. '''

  5. from flask import Flask
  6. from flask import request
  7. from flask import render_template


  8. app = Flask(__name__)

  9. @app.route('/', methods=['GET','POST'])
  10. def home():
  11.     return render_template('home.html')

  12. @app.route('/signin',methods=['GET'])
  13. def signin_from():
  14.     return render_template('form.html')

  15. @app.route('/signin',methods=['POST'])
  16. def signin():
  17.     username=request.form['username']
  18.     password=request.form['password']
  19.     if username == 'admin' and password == 'password':
  20.         return render_template('signok.html',username=username)
  21.     return render_template('form.html', message='Bad username and password', username=username)

  22. if __name__ == '__main__':
  23.     app.run()
上篇python flask web服务使用MVC思想重构
上篇python flask web服务使用MVC思想重构
上篇python flask web服务使用MVC思想重构
上篇python flask web服务使用MVC思想重构
上篇python flask web服务使用MVC思想重构