Flask-security: NameError: name 'login_required' is not defined

Created on 3 Sep 2012  路  2Comments  路  Source: mattupstate/flask-security

Trying to run the example with MongoDB as the datastore.

from flask import Flask
from flask.ext.mongoengine import MongoEngine
from flask.ext.security import Security
from flask.ext.security.datastore.mongoengine import MongoEngineUserDatastore

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret'
app.config['MONGODB_DB'] = 'auth_test'
app.config['MONGODB_HOST'] = 'ds035997.mongolab.com'
app.config['MONGODB_PORT'] = 35997

db = MongoEngine(app)
Security(app, MongoEngineUserDatastore(db))

@app.before_first_request
def before_first_request():
    user_datastore.create_role(name='admin')
    user_datastore.create_user(username='asselinpaul', email='[email protected]',
                               password='paa1946', roles=['admin'])


@app.route("/login")
def login():
    return render_template('login.html', form=LoginForm())

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

I've install Flask and Flask-Security through virtualenv and can't see what's wrong, any help?

Thanks in advance.
Paul

Most helpful comment

You'll need to import login_required ofcourse. Like this:
from flask.ext.security import login_required

All 2 comments

You'll need to import login_required ofcourse. Like this:
from flask.ext.security import login_required

Thanks, I'll give it a shot

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adamlwgriffiths picture adamlwgriffiths  路  5Comments

lormayna picture lormayna  路  5Comments

tim-hub picture tim-hub  路  4Comments

Galstat picture Galstat  路  3Comments

ochronus picture ochronus  路  4Comments