python - flask報(bào)錯(cuò)ValueError: invalid key ’nicknickname’
問(wèn)題描述
提出一個(gè)問(wèn)題,也順便記錄一下~,因?yàn)樯婕暗降奈募容^多,所以只貼部分代碼:下面是views文件:
#coding=utf-8from flask import render_template, flash, redirect, session, url_for, request, gfrom flask_login import login_user, logout_user, current_user, login_requiredfrom app import app, db, lm, oidfrom .forms import LoginFormfrom .models import User@lm.user_loaderdef load_user(id): return User.query.get(int(id))@app.before_requestdef before_request(): g.user = current_user@app.route(’/’)@app.route(’/index’)@login_requireddef index(): user = {’nickname’: ’anryan’} posts = [{ ’author’: {’nickname’: ’Anryan’}, ’body’: u’這地方不錯(cuò)~’},{ ’author’: {’nickname’: ’syy’}, ’body’: u’晚上能扎營(yíng)不’}, { ’author’: {’nickname’: u’小麥’}, ’body’: u’空氣很清爽哈~’}, { ’author’: {’nickname’: u’老崔’}, ’body’: u’誰(shuí)說(shuō)不是,如果Tara能在這兒辦場(chǎng)演唱會(huì)就好了’},{ ’author’: {’nickname’: u’二又’}, ’body’: u’在這兒打LOL比賽肯定能贏’},{ ’author’: {’nickname’: u’言神’}, ’body’: u’玩王者榮耀也不錯(cuò)。’} ] return render_template(’index.html’, title=’Home’, user=user, posts=posts)@app.route(’/login’, methods=[’GET’, ’POST’])@oid.loginhandlerdef login(): if g.user is not None and g.user.is_authenticated:return redirect(url_for(’index’)) form = LoginForm() if form.validate_on_submit():session[’remember_me’] = form.remember_me.datareturn oid.try_login(form.openid.data, ask_for=[’nicknickname’, ’email’]) return render_template(’login.html’, title=u’點(diǎn)擊進(jìn)入’, form=form, providers=app.config[’OPENID_PROVIDERS’])@oid.after_logindef after_login(resp): if resp.email is None or resp.email == '':flash(u’無(wú)效登陸信息哦~請(qǐng)重新輸入’)return redirect(url_for(’login’)) user = User.query.filter_by(email=resp.email).first() if user is None:nicknickname = resp.nicknicknameif nicknickname is None or nicknickname == '': nicknickname = resp.email.split(’@’)[0]user = User(nicknickname=nicknickname, email=resp.email)db.session.add(user)db.session.commit() remember_me = False if ’remember_me’ in session:remember_me = session[’remember_me’]session.pop(’remember_me’, None) login_user(user, remember=remember_me) return redirect(request.args.get(’next’) or url_for(’index’))@app.route(’/logout’)def logout(): logout_user() return redirect(url_for(’index’))
顯示頁(yè)面:
頁(yè)面報(bào)錯(cuò):
File 'C:UsersAsusflaskblogappviews.py', line 64, in loginOpen an interactive python shell in this framereturn oid.try_login(form.openid.data, ask_for=[’nicknickname’, ’email’])File 'C:UsersAsusflasklibsite-packagesflask_openid.py', line 554, in try_loginapprove the trust root).'''if ask_for and __debug__: for key in ask_for:if key not in ALL_KEYS: raise ValueError(’invalid key %r’ % key) if ask_for_optional:for key in ask_for_optional: if key not in ALL_KEYS:raise ValueError(’invalid optional key %r’ % key)try:ValueError: invalid key ’nicknickname’The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.To switch between the interactive traceback and the plaintext one, you can click on the 'Traceback' headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.
You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:
問(wèn)題解答
回答1:這里不應(yīng)該是nickname嗎?
相關(guān)文章:
1. 哪位大神知道MySql怎么修改多行多列的數(shù)據(jù)?求指點(diǎn)2. 這是什么情況???3. 編輯管理員信息時(shí),為什么沒(méi)有修改過(guò)的內(nèi)容會(huì)為空?4. phpadmin的數(shù)據(jù)庫(kù),可以設(shè)置自動(dòng)變化時(shí)間的變量嗎?就是不需要接收時(shí)間數(shù)據(jù),自動(dòng)變化5. mysql - thinkphp5 在MAC電腦本地正常,部署LINUX服務(wù)器之后,模型不存在6. 老哥們求助啊7. javascript - 百度圖片切換圖片時(shí)url會(huì)改變,但無(wú)刷新,沒(méi)用hash,IE8也支持,請(qǐng)問(wèn)是用了什么技術(shù)?8. PHP類封裝的插入數(shù)據(jù),總是插入不成功,返回false;9. APP上傳到電腦服務(wù)器,出現(xiàn)數(shù)據(jù)上傳不完整的問(wèn)題10. 求救一下,用新版的phpstudy,數(shù)據(jù)庫(kù)過(guò)段時(shí)間會(huì)消失是什么情況?
