title: The weird question problem of flask-login when using flask redirect
body: <p>I found a problem when using the flask-login.When I ran the program in the firefox, it shows
  the register page and I login with my username and password. But the app cannot redirect normally! It redirected to my login page again!!! And more suprise thing is that it runs perfectly when I clean all the data in firefox and restart the app.</p>
  <p>A picture about the running:</p>
  <p><a href="https://i.stack.imgur.com/T1KBe.png" rel="nofollow noreferrer">Some logs</a></p>
  <p>Here are my code.</p>
  <pre class="lang-py prettyprint-override"><code>from flask import Flask, redirect, render_template, url_for, request
  from flask_login import login_required, login_user, logout_user, LoginManager, UserMixin
  from settings import DevelopMentConfig
  from flask_sqlalchemy import SQLAlchemy
  
  app = Flask(__name__)
  app.config.from_object(DevelopMentConfig())
  db = SQLAlchemy(app)
  login_manager = LoginManager(app)
  login_manager.login_view = 'login'
  
  
  class User(db.Model, UserMixin):
      id = db.Column('id', db.Integer, primary_key=True, autoincrement=True)
      username = db.Column('username', db.String(120))
      password = db.Column('password', db.String(120))
  
      def __init__(self, username=None, password=None):
          self.username = username
          self.password = password
  
  
  @login_manager.user_loader
  def load_user(id):
      return User.query.get(int(id))
  
  
  @app.route('/index')
  @login_required
  def index():
      return 'Welcome'
  
  
  @app.route('/login', methods=['GET', 'POST'], endpoint='login')
  def login():
      if request.method == 'POST':
          username = request.form.get('username')
          password = request.form.get('password')
          if username == 'xiaoshulin' and password == '123456':
              user = User.query.filter_by(username=username).first()
              login_user(user)
              return redirect(url_for('index'))
      return render_template('login.html')
  
  
  @app.route('/logout')
  @login_required
  def logout():
      logout_user()
      return redirect('/login')
  
  
  if __name__ == &quot;__main__&quot;:
      # db.create_all()
      app.run()
  </code></pre>
  <p>This is the login html code.</p>
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;title&gt;Login Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Login&lt;/h1&gt;
      &lt;form method=&quot;post&quot;&gt;
          &lt;input type=&quot;text&quot; name=&quot;username&quot;&gt;
          &lt;input type=&quot;password&quot; name=&quot;password&quot;&gt;
          &lt;input type=&quot;submit&quot; value=&quot;submit&quot;&gt;
      &lt;/form&gt;
      &lt;br&gt;
      &lt;p&gt;{{ message }}&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>