Note that there are some explanatory texts on larger screens.

plurals
  1. POdecorator require doens't work correctly in flask-principal in my sample
    primarykey
    data
    text
    <p>I have problem with decorator require(http_exception=401) in flask-principal. I am trying to access to site which requires login, but I am able to access there. Do you have any idea why? My code following:</p> <p>infrastructure.py</p> <pre><code>app = Flask(__name__) db = SQLAlchemy(app) principals = Principal(app) principals._init_app(app) # User Information providers @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): g.user = User.query.from_identity(identity) # Permission admin = Permission(RoleNeed('admin')) member_perm = Permission(RoleNeed('member')) User = get_user_class(db.Model) </code></pre> <p>views/login.py</p> <pre><code># -*- coding: utf-8 -*- from flask import Flask, request, session, g, redirect, url_for, \ abort, render_template, flash, current_app from flask.ext.principal import identity_changed, Identity from hlidejkatastr.infrastructure import app, User @app.route('/login/', methods=['GET', 'POST']) def login(): if request.method == 'POST': email = request.form['email'] user = User.query.filter(User.email==email).first() if user is not None: if user.password == request.form['password']: identity_changed.send(current_app._get_current_object(), identity=Identity(user.id)) return redirect(url_for('profil')) else: return render_template('login.html') else: return render_template('login.html') return render_template('login.html') </code></pre> <p>views/profil.py</p> <pre><code>@member_perm.require(http_exception=401) @app.route('/profil/', methods=['GET', 'POST']) def profil(): # code ... </code></pre> <p>Thank you for you advice.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload