I have an example Flask app that basically works. Base URL ( /) does not require authentication; however, I have a resource in /auth/securedthat requires authentication.
The application works very well while the user is logged in; however, it throws werkzeug.routing.BuildError (BuildError: Could not build url for endpoint 'login' with values ['next']. Did you mean 'auth.login' instead?)when someone tries to access /auth/securedas an unauthenticated user, because I encoded it as follows:
@auth.route('/secured')
@ldap.login_required
def secured():
return 'Login Success! {0}'.format(session)
I am using Flask Blueprints for my URL routing ... I assumed this should work ...
def create_app(config_name):
from .main import main as main_blueprint
from .auth import auth as auth_blueprint
app = Flask(__name__)
app.config.from_object(config[config_name])
config[config_name].init_app(app)
bootstrap.init_app(app)
db.init_app(app)
ldap.init_app(app)
app.register_blueprint(main_blueprint)
app.register_blueprint(auth_blueprint, url_prefix='/auth')
return app
The application catalog is constructed as follows:
testapp/
|
+ config.py
+ manage.py
+ app/
|
+ __init__.py
+ auth/
|
+ __init__.py
+ views.py
+ main/
|
+ __init__.py
+ views.py
As far as I can tell, something went wrong in my project registration; however, I do not understand where the error is.
URL /auth/login, /auth/secured ?