8.Python编写登录接口
2021-07-19 07:06
标签:form cal .com div use 通过 cat word ret 1.python需安装flask,在命令行窗口输入:pip3 install flask 2.代码如下所示: 3.实现效果: 8.Python编写登录接口 标签:form cal .com div use 通过 cat word ret 原文地址:https://www.cnblogs.com/android-it/p/9523548.htmlfrom flask import Flask,request,jsonify,session
USERNAME = ‘admin‘
PASSWORD = ‘123456‘
VERIFICATIONCODE = ‘111111‘
app = Flask(__name__)
app.secret_key=‘pithy‘
@app.route(‘/loginNancy‘,methods=[‘GET‘,‘POST‘])
def loginNancy():
error = None
if request.method == ‘POST‘:
if request.form[‘username‘] != USERNAME:
error = ‘Invalid username‘
elif request.form[‘password‘] !=PASSWORD:
error = ‘Invalid password‘
elif request.form[‘verificationCode‘] != VERIFICATIONCODE:
error = ‘Invalid verificationCode‘
else:
session[‘logged_in‘] = True
return jsonify({‘code‘:‘200‘,‘msg‘:‘success‘})
return jsonify({‘code‘:‘400‘,‘msg‘:‘error‘})
if __name__ == ‘__main__‘: #若不加host=‘0.0.0.0‘则无法通过ip访问接口,只能通过127.0.0.1或者localhost访问
app.run(debug=True,host=‘0.0.0.0‘) #debug=True,调试模式,修改代码中的输出后,可以自动重载代码并显示调试信息
上一篇:C#自定义处理xml数据类实例