2016-07-14 102 views
0

如何與成功註冊重定向到一個不同的html頁面比默認值:「/」 重定向說登錄的用戶的個人資料頁如何成功登錄後重定向並註冊在Flask-Security中?和錯誤

,並註冊後,我有這樣的錯誤

AttributeError: 'NoneType' object has no attribute 'send'

Traceback (most recent call last): 

    File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner 

    File "/usr/lib/python2.7/threading.py", line 754, in run 

    File "/home/maharshi/.local/lib/python2.7/site-packages/werkzeug/serving.py", line 659, in inner 

    File "/home/maharshi/.local/lib/python2.7/site-packages/werkzeug/serving.py", line 499, in serve_forever 

    File "/usr/lib/python2.7/SocketServer.py", line 236, in serve_forever 

    File "/usr/lib/python2.7/threading.py", line 585, in set 

    File "/usr/lib/python2.7/threading.py", line 407, in notifyAll 

<type 'exceptions.TypeError'>: 'NoneType' object is not callable 

數據獲得註冊,但此錯誤仍然存​​在。

from flask import Flask 
from flask_sqlalchemy import SQLAlchemy 
from flask import render_template 
from flask import request, redirect, url_for 
from flask_security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin, login_required 
import datetime 


#Create app 
app= Flask(__name__) 
app.config['DEBUG']= True 
app.config['SQLALCHEMY_DATABASE_URI']= 'postgresql://postgres:[email protected]/pdb1' 
app.config['SECRET_KEY']= 'MaharshI' 
app.config['SECURITY_REGISTERABLE'] = True 

#Create database connection object 
db= SQLAlchemy(app) 

#Define models 
roles_users= db.Table('roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), 
    db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) 

class Role(db.Model, RoleMixin): 
    id= db.Column(db.Integer(), primary_key=True) 
    name= db.Column(db.String(80), unique=True) 
    description= db.Column(db.String(225)) 

class User(db.Model, UserMixin): 
    id = db.Column(db.Integer, primary_key=True) 
    email = db.Column(db.String(255), unique=True) 
    password = db.Column(db.String(255)) 
    active = db.Column(db.Boolean()) 
    confirmed_at = db.Column(db.DateTime()) 
    roles= db.relationship('Role', secondary=roles_users, backref=db.backref('user',lazy='dynamic')) 

#setup Flask-Security 
user_datastore= SQLAlchemyUserDatastore(db, User, Role) 
security= Security(app, user_datastore) 

# @app.before_first_request 
# def create_user(): 
# user_datastore.create_user(email='[email protected]', password='pass') 
# db.session.commit() 

@app.route('/') 
def home(): 
    return render_template('home.html') 

@app.route('/profile/<email>') 
@login_required 
def profile(email): 
    user= User.query.filter_by(email=email).first() 
    return render_template('profile.html', user=user) 

# SECURITY_POST_LOGIN_VIEW= 'snd.html' 


# @app.route('/login_form') 
# def login_form(): 
# SECURITY_POST_LOGIN_VIEW= '/templates/snd.html' 
# return render_template(url_for(SECURITY_POST_LOGIN_VIEW)) 

# @app.route('/post_user', methods=['POST']) 
# def post_user(): 
# user=User(request.form['email'], request.form['password']) 
# db.session.add(user) 
# db.session.commit() 
# return redirect(url_for('home')) 


if __name__ == "__main__": 
    app.run(host='0.0.0.0') 
+0

@ security.login_context_processor DEF security_login_processor(): \t SECURITY_POST_LOGIN_VIEW = '/templates/snd.html' \t返回render_template(url_for(SECURITY_POST_LOGIN_VIEW))#IS這種密切??? – maharshi

+0

發佈整個錯誤追溯,而不僅僅是最終的錯誤消息。 –

+0

@JohnGordon請看看... – maharshi

回答

0

我認爲錯誤是因爲雜項設置「SECURITY_SEND_REGISTER_EMAIL」默認爲真,導致您的應用程序試圖發送郵件報名註冊成功的結果。如果您還沒有使用應用程序實例初始化瓶子郵件,則會引發此異常。

AttributeError: 'NoneType' object has no attribute 'send'

設置「SECURITY_SEND_REGISTER_EMAIL = False」解決了這個問題。