title: Flask authentication with Flask-Security
body: <p>Trying to enable login in flask with flask-security. The following code works fine (I import in <code>__init__.py</code>)</p>
  
  <pre><code>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())
  </code></pre>
  
  <p>If, however, I change <code>user = Blueprint('user', __name__)</code> to <code>user = Blueprint('user', __name__, url_prefix='/blah')</code> it fails with a <code>werkzeug.routing.BuildError BuildError: ('auth.authenticate', {}, None)</code>. url_for is the problem, however, I don't understand why. HALP!</p>