title: Flask Error: “Method Not Allowed The method is not allowed for the requested URL” (Login and Home Page)
body: <pre><code>@app.route("/")
  @app.route("/home",methods=['GET', 'POST'])
  def home():
  if current_user.is_authenticated:
      posts=mongo.db.articles
      #allpost=posts.find().limit(5)
      it=current_user.user_json['interest']
      allpost=posts.find( {'NewsType': it } ).limit(10)
      #flash(session['email'])
  
      return render_template('home.html', posts=allpost)
  return render_template('login.html', title='Login',form=LoginForm()) 
  </code></pre>
  
  <p>This is my code for the Home Page</p>
  
  <pre><code>@app.route("/login", methods=['GET', 'POST'])
  def login():
  if current_user.is_authenticated:
      return redirect(url_for('home'))
  form = LoginForm()
  if form.validate_on_submit():
      users = mongo.db.users
      loginuser_json = users.find_one({'email': form.email.data})
      if loginuser_json and bcrypt.check_password_hash(loginuser_json['password'], form.password.data):
          # Create a custom user and pass it to login_user:
          loginuser = User(loginuser_json)
          login_user(loginuser,duration=d)
          next_page = request.args.get('next')
          return redirect(next_page) if next_page else redirect(url_for('home'))
          return redirect(url_for('home'))
      else:
          flash('Login Unsuccessful. Please check username and password', 'danger')
  return render_template('login.html', title='Login', form=form)
  </code></pre>
  
  <p>and this for the login route </p>
  
  <p>When i write localhost:5000 in the browser it opens Login Page (because if user is not authenticated it should go to login page first)</p>
  
  <p>But when i try to login from this page , it is giving an error "Method Not Allowed.The method is not allowed for the requested URL."</p>
  
  <p>What should i do </p>