Posez une question et enregistrez-la en passant~ Parce qu'il y a de nombreux fichiers impliqués, je ne publie qu'une partie du code :
Voici le fichier de vues :
#coding=utf-8
from flask import render_template, flash, redirect, session, url_for, request, g
from flask_login import login_user, logout_user, current_user, login_required
from app import app, db, lm, oid
from .forms import LoginForm
from .models import User
@lm.user_loader
def load_user(id):
return User.query.get(int(id))
@app.before_request
def before_request():
g.user = current_user
@app.route('/')
@app.route('/index')
@login_required
def index():
user = {'nickname': 'anryan'}
posts = [
{
'author': {'nickname': 'Anryan'},
'body': u'这地方不错~'
},
{
'author': {'nickname': 'syy'},
'body': u'晚上能扎营不'
},
{
'author': {'nickname': u'小麦'},
'body': u'空气很清爽哈~'
},
{
'author': {'nickname': u'老崔'},
'body': u'谁说不是,如果Tara能在这儿办场演唱会就好了'
},
{
'author': {'nickname': u'二又'},
'body': u'在这儿打LOL比赛肯定能赢'
},
{
'author': {'nickname': u'言神'},
'body': u'玩王者荣耀也不错。'
}
]
return render_template('index.html',
title='Home',
user=user,
posts=posts)
@app.route('/login', methods=['GET', 'POST'])
@oid.loginhandler
def 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.data
return oid.try_login(form.openid.data, ask_for=['nicknickname', 'email'])
return render_template('login.html',
title=u'点击进入',
form=form,
providers=app.config['OPENID_PROVIDERS'])
@oid.after_login
def after_login(resp):
if resp.email is None or resp.email == "":
flash(u'无效登陆信息哦~请重新输入')
return redirect(url_for('login'))
user = User.query.filter_by(email=resp.email).first()
if user is None:
nicknickname = resp.nicknickname
if 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'))
Afficher la page :
Erreur de page :
File "C:\Users\Asus\flask\blog\app\views.py", line 64, in login
Open an interactive python shell in this framereturn oid.try_login(form.openid.data, ask_for=['nicknickname', 'email'])
File "C:\Users\Asus\flask\lib\site-packages\flask_openid.py", line 554, in try_login
approve 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.
Vous pouvez exécuter du code Python arbitraire dans les cadres de pile et des aides supplémentaires sont disponibles pour l'introspection :
Est-ce que cela ne devrait pas être un surnom ?