title: Why i get 302 error on flask.redirect
body: <p>I have this code <a href="https://github.com/italomaia/flask-empty/blob/master/src/0.8/main.py" rel="nofollow">https://github.com/italomaia/flask-empty/blob/master/src/0.8/main.py</a> and i written at end of file this code </p>
  
  <pre><code>def configure_before_request(app):
      @app.before_request
      def before_request():
          hash = pbkdf2_sha256.encrypt(app.config['PASSWORD'], rounds=8000, salt_size=10)
          if session.get('logged_in') != hash:
              return redirect(url_for('login'))
  def configure_views(app):
      @app.route('/login/', methods=['GET', 'POST'])
      def login():
          if request.method == 'POST':
              hash = pbkdf2_sha256.encrypt(app.config['PASSWORD'], rounds=8000, salt_size=10)
              if request.form['login'] == app.config['USERNAME'] and pbkdf2_sha256.verify(request.form['password'], hash):
                  session['logged_in'] = hash
                  return redirect(url_for('index'))
              else:
                  flash(u'Неверный логин или пароль')
          return render_template('login.html')
  
      @app.route('/', methods=['GET', 'POST'])
      def index():
          return 'index_page НАХ.'
  </code></pre>
  
  <p>if i run this code, i get 302 server error (<code>ERR_TOO_MANY_REDIRECTS</code>), but if i change this line <code>return redirect(url_for('login'))</code> on <code>return 'Hello!'</code> all be work without errors! What i do wrong? </p>
  
  <p>Thanks. </p>
  
  <p>EDIT
  Solution problem. </p>
  
  <p>replace
  <code>if session.get('logged_in') != hash:</code>
  on
  <code>if session.get('logged_in') != hash and request.endpoint != 'login':</code></p>