title: Python's Flask Registration Post method 404 error
body: <p>Hello everybody I am new to Flask and I am writing this program and the registration functionality is not working and the error message is really not helping me much so here is the code, error and html view so, anything will be really helpful. python code:</p>
  <pre><code>@app.route(&quot;/register&quot;, methods=[&quot;GET&quot;, &quot;POST&quot;])
  def register():
      if request.method == &quot;GET&quot;:
          return render_template(&quot;register.html&quot;)
  
      else:
          # check for username
          if not request.form.get(&quot;username&quot;):
              return apology(&quot;Must provide valid username&quot;)
  
          #  check for valid password
          elif not request.form.get(&quot;password&quot;):
              return apology(&quot;Must provide valid password&quot;)
  
          # check password matches
          elif not request.form.get(&quot;password&quot;) == request.form.get(&quot;password_confirmation&quot;):
              return apology(&quot;Password doesn't match&quot;)
  
          hash = generate_password_hash(request.form.get(&quot;password&quot;))
          new_user = db.execute(&quot;INSERT INTO users (username, hash) VALUES (:username, :hash)&quot;, username = request.form.get(&quot;username&quot;), hash = hash)
  
          if not new_user:
              return apology(&quot;Username take&quot;)
  
          session[&quot;user_id&quot;] = new_user
  
          flash(&quot;Welcome!&quot;)
  
          return redirect(&quot;/&quot;)
  
  </code></pre>
  <p>Html form:</p>
  <pre><code>{% extends &quot;layout.html&quot; %}
  
  {% block title %}
      register
  {% endblock %}
  
  {% block main %}
      &lt;form action=&quot;/register&quot; method=&quot;post&quot;&gt;
          &lt;div class=&quot;form-group&quot;&gt;
              &lt;input autocomplete=&quot;off&quot; autofocus class=&quot;form-control&quot; name=&quot;username&quot; placeholder=&quot;Username&quot; type=&quot;text&quot;&gt;
          &lt;/div&gt;
          &lt;div class=&quot;form-group&quot;&gt;
              &lt;input class=&quot;form-control&quot; name=&quot;password&quot; placeholder=&quot;Password&quot; type=&quot;password&quot;&gt;
              &lt;input name=&quot;password_confrimation&quot; placeholder=&quot;Confirm Password&quot; type=&quot;password&quot;&gt;
          &lt;/div&gt;
          &lt;input type=&quot;submit&quot;&gt;
      &lt;/form&gt;
  {% enblock %}
  </code></pre>
  <p>the logs and message:</p>
  <pre><code>[2020-07-13T18:19:20.336Z]  &quot;GET /templates/&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36&quot;
  [2020-07-13T18:19:21.732Z]  &quot;GET /templates/register.html&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36&quot;
  [2020-07-13T18:19:32.272Z]  &quot;POST /register&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36&quot;
  [2020-07-13T18:19:32.273Z]  &quot;POST /register&quot; Error (404): &quot;Not found&quot;
  </code></pre>
  <p>NOTE: the database is already connected with the db file.</p>