title: Flask: Don't redirect to Url
body: <p>I'm starting with Flask and have this problem. I need make a redirect to url. When I try with this code, work good:</p>
  
  <pre><code>@app.route('/fa')
  def hello():
      return redirect(url_for('foo'))
  
  @app.route('/foo')
  def foo():
      return 'Hello Foo!'
  </code></pre>
  
  <p>But now, I need this same but with a render template. This is the code, but then I but the user, flask redirect and give this error: Method Not Allowed</p>
  
  <pre><code>from flask import Flask, render_template, redirect, url_for
  from forms import MyForm
  
  app = Flask(__name__)
  app.config.from_object(__name__)
  @app.route('/')
  def home():
    return render_template('home.html')
  
  @app.route('/about')
  def about():
    return render_template('about.html')
  
  @app.route("/signin", methods=("GET", "POST"))
  def signin():
    form = MyForm()
    if request.method == 'POST':
      if form.validate() == True:
        return redirect(url_for('foo'))
    elif request.method == 'GET':
      return render_template("signin.html", form=form)
  
  
  if __name__ == "__main__":
    app.debug = True
    app.run()
  </code></pre>
  
  <p>signin.html</p>
  
  <pre><code>{% block content %}
    &lt;h2&gt;Sign In&lt;/h2&gt;
  
    &lt;form method="POST" action="{{ url_for('signin') }}"&gt;
  
    {{ form.hidden_tag() }}
  
    {{ form.username.label }}
    {{ form.username(size=20) }}
  
    {{ form.password.label }}
    {{ form.password(size=20) }}
  
    {{ form.submit }}
    &lt;/form&gt;
  
  {% endblock %}
  </code></pre>
  
  <p>MyForm.py</p>
  
  <pre><code>from flask_wtf import Form, TextField, PasswordField, DataRequired, SubmitField
  
  class MyForm(Form):
    username = TextField("Username", validators=[DataRequired()])
    password = PasswordField("Password", validators=[DataRequired()])
    submit = SubmitField("Sign In")
  
  def validate(self):    
      user = "franco"
      if user == self.username:
          return True
      else:
          return False
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code> ValueError
   ValueError: View function did not return a response
  </code></pre>
  
  <p>Why?? Thanks</p>