嘗試啓用燒瓶安全驗證登錄。下面的代碼工作正常(我導入__init__.py
)使用Flask-Security進行燒瓶驗證
from flask import Blueprint, render_template, request, redirect, url_for
from coursly import app
from coursly.models import *
from flask.ext.security import Security, LoginForm, SQLAlchemyUserDatastore
user_datastore = SQLAlchemyUserDatastore(db, user.User, user.Role)
Security(app, user_datastore)
user = Blueprint('user', __name__)
@user.route('/')
def index():
return redirect(url_for("user.login"))
@user.route('/login', methods=['GET', 'POST'])
def login():
return render_template('user/login.html', content='Login Page', action=url_for('auth.authenticate'), form=LoginForm())
但是,如果我改變user = Blueprint('user', __name__)
到user = Blueprint('user', __name__, url_prefix='/blah')
失敗了werkzeug.routing.BuildError BuildError: ('auth.authenticate', {}, None)
。 url_for是問題,但是,我不明白爲什麼。 HALP!
你應該接受你的答案,即使是你自己的。這樣它在SO上適當地顯示爲「回答」。 – exhuma