这是我的登录代码。当我尝试使用其他函数中的会话检索它时返回null。为什么?
@app.route('/login', methods=['POST'])
def login():
jsn = json.loads(request.data)
res = spcall('login', (
jsn['email'],
jsn['password'],), True)
if 'Login successful' in str(res):
session['logged_in'] = True
session['user'] = get_userbyemail(jsn['email'])
session['email'] = session['user'][0][0]
session['user_id'] = session['user'][0][1]
session['first_name'] = session['user'][0][2]
session['is_admin'] = session['user'][0][7]
session['is_customer'] = session['user'][0][8]
recsuser = []
for r in session['user']:
recsuser.append({'email': str(r[0]), 'user_id': str(r[1]), 'first_name': str(r[2]), 'last_name': str(r[3]),
'address1': str(r[4]), 'address2': str(r[5]), 'mobile_no': str(r[6]),
'is_admin': str(r[7]), 'is_customer': str(r[8])})
return jsonify({'status': 'Login successful', 'message': res[0][0], 'userinfo': recsuser, 'countuserinfo': len(recsuser), 'brands': recsbrand, 'countbrands': len(recsbrand), 'is_admin': session['is_admin'],
'is_customer': session['is_customer'], 'email':session['email']})
当我检索值email,user_id,first_name,is_admin,is_customer时,它返回null。
以下是我检索会话值的代码。
@app.route('/car/platenumber/<string:car_plate_number>', methods=['GET'])
def get_carbyplatenumber(car_plate_number):
res = spcall('get_carbyplatenumber', (car_plate_number,), )
if 'Error' in str(res[0][0]):
return jsonify({'status': 'Error', 'message': res[0][0]})
recs = []
for r in res:
recs.append({'car_plate_number': str(r[0]), 'car_color': str(r[1]), 'car_brandname': str(r[2]), 'car_model': str(r[3]), 'car_rental_rate': str(r[4]),
'car_image': str(r[5]), 'car_owner_id': r[6], 'car_category_name': str(r[7])})
user = {'user_id': session.get('user_id'), 'first_name': session.get('first_name')}
recsuser = []
recsuser.append({'user':user})
print recsuser
return jsonify({'status': 'Ok', 'entries': recs, 'count': len(recs), 'recsuser': user})