from 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,调试模式,修改代码中的输出后,可以自动重载代码并显示调试信息