一個簡單的flask的接口
阿新 • • 發佈:2018-01-14
flask odin method Coding main orm methods file 對象
#!flask/bin/python from flask import Flask from flask import request app = Flask(__name__) @app.route(‘/‘, methods = [‘GET‘,‘POST‘]) def home(): return ‘<h1>hello</h1>‘ @app.route(‘/signin‘,methods = [‘GET‘]) def signin_form(): return ‘‘‘ <form action="/signin" method="post"> <p><input name="username"></p> <p><input name="password" type="password"></p> <p><button type="submit">Sign In</button></p> </form>‘‘‘ @app.route(‘/signin‘ , methods=[‘POST‘]) def signin(): # 需要從request對象讀取表單內容: if request.form[‘username‘] == ‘admin‘ and request.form[‘password‘] == ‘password‘: return ‘<h3>Hello, admin!</h3>‘ return ‘<h3>Bad username or password.</h3>‘ @app.route(‘/1‘ , methods=[‘POST‘]) def aa(): #傳什麽返回什麽 with open(‘1.txt‘,‘a‘) as f: print(str(request.data, encoding=‘utf-8‘),file=f) return request.data if __name__==‘__main__‘: app.run(port=3002)#默認不填寫的話,是5000端口
一個簡單的flask的接口