You can tell Flask-Principal that you want to raise the HTTP error code instead:
@app.route('/admin') @admin_permission.require(http_exception=403) def admin(request):
Now flask.abort() will be called instead of raising PermissionDenied . For error code 403, you can register an error handler :
@app.errorhandler(403) def page_not_found(e): session['redirected_from'] = request.url return redirect(url_for('users.login'))
where url_for('users.login') will return the route url for the login page.
source share