title: Error: The function either returned None or ended without a return statement. but not found where?
body: <p>I am trying to update my database data based on data submitted from the form a user fills out, but I am receiving this <strong>error</strong>:</p>
  
  <blockquote>
    <p>[TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.]</p>
  </blockquote>
  
  <p><strong>Error Stack Trace:</strong></p>
  
  <pre><code>Traceback (most recent call last):
        File "C:\Users\thanaphonsae\PycharmProjects\Kudson\venv\lib\site-packages\flask\app.py", line 2309, in __call__
          return self.wsgi_app(environ, start_response)
        File "C:\Users\thanaphonsae\PycharmProjects\Kudson\venv\lib\site-packages\flask\app.py", line 2295, in wsgi_app
          response = self.handle_exception(e)
        File "C:\Users\thanaphonsae\PycharmProjects\Kudson\venv\lib\site-packages\flask\app.py", line 1741, in handle_exception
          reraise(exc_type, exc_value, tb)
        File "C:\Users\thanaphonsae\PycharmProjects\Kudson\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
          raise value
        File "C:\Users\thanaphonsae\PycharmProjects\Kudson\venv\lib\site-packages\flask\app.py", line 2292, in wsgi_app
          response = self.full_dispatch_request()
        File "C:\Users\thanaphonsae\PycharmProjects\Kudson\venv\lib\site-packages\flask\app.py", line 1816, in full_dispatch_request
          return self.finalize_request(rv)
        File "C:\Users\thanaphonsae\PycharmProjects\Kudson\venv\lib\site-packages\flask\app.py", line 1831, in finalize_request
          response = self.make_response(rv)
        File "C:\Users\thanaphonsae\PycharmProjects\Kudson\venv\lib\site-packages\flask\app.py", line 1957, in make_response
          'The view function did not return a valid response. The'
      TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
  </code></pre>
  
  <p>This is my <strong>HTML form</strong>: </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;center&gt;
  &lt;tbody&gt;
  
  &lt;table id="myTable" class="table table-sm" cellspacing="0"&gt;
  &lt;form action ="{{ url_for('editid',id=rows[0])}}" method="POST"&gt;
  
      &lt;h1&gt;ร้านสาขา {{rows[2]}}&lt;/h1&gt;
  
      ผลการแก้ไขข้อมูล: {{ msg }}
  
  &lt;thead class="thead-dark"&gt;
      &lt;tr class="header active"&gt;
          &lt;th scope="col"&gt;&lt;input name="date" value="{{rows[1]}}"&gt;&lt;/th&gt;
          &lt;th scope="col"&gt;PMA&lt;/th&gt;
          &lt;th scope="col"&gt;UPSD&lt;/th&gt;
          &lt;th scope="col"&gt;BPSD&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/thead&gt;
      &lt;tbody&gt;
  
      &lt;tr&gt;
          &lt;th scope="row"&gt;เช้า&lt;/th&gt;
          &lt;td&gt;62&lt;/td&gt;
          &lt;td&gt;&lt;input name="mo_62_upsd" value="{{rows[3]}}"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input name="mo_62_bpsd" value="{{rows[4]}}"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;&lt;/tr&gt;
      &lt;tr&gt;
          &lt;th scope="row"&gt;เช้า&lt;/th&gt;
          &lt;td&gt;87&lt;/td&gt;
          &lt;td&gt;&lt;input name="mo_87_upsd" value="{{rows[5]}}"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input name="mo_87_bpsd" value="{{rows[6]}}"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;th scope="row"&gt;บ่าย&lt;/th&gt;
          &lt;td&gt;62&lt;/td&gt;
          &lt;td&gt;&lt;input name="af_62_upsd" value="{{rows[7]}}"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input name="af_62_bpsd" value="{{rows[8]}}"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;th scope="row"&gt;บ่าย&lt;/th&gt;
          &lt;td&gt;87&lt;/td&gt;
          &lt;td&gt;&lt;input name="af_87_upsd" value="{{rows[9]}}"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input name="af_87_bpsd" value="{{rows[10]}}"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;th scope="row"&gt;ดึก&lt;/th&gt;
          &lt;td&gt;62&lt;/td&gt;
          &lt;td&gt;&lt;input name="ev_62_upsd" value="{{rows[11]}}"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input name="ev_62_bpsd" value="{{rows[12]}}"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;th scope="row"&gt;ดึก&lt;/th&gt;
          &lt;td&gt;87&lt;/td&gt;
          &lt;td&gt;&lt;input name="ev_87_upsd" value="{{rows[13]}}"&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input name="ev_87_bpsd" value="{{rows[14]}}"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;&lt;/tr&gt;
  &lt;center&gt;
      &lt;td width="50%"&gt;&lt;input type="submit" value="submit"/&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;/tr&gt;
      &lt;td&gt;&lt;a href = "/kudson/update"&gt;กลับหน้าหลัก&lt;/a&gt;&lt;/td&gt;
  &lt;/center&gt;
      &lt;/tbody&gt;
  &lt;/form&gt;
  &lt;/table&gt;
  &lt;/center&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and this is my <strong>Python route code</strong>:</p>
  
  <pre><code>@app.route('/kudson/edit/&lt;id&gt;', methods=['POST', 'GET'])
  def editid(id):
          if request.method == 'POST':
              pass
          else:
              try:
                  id = request.form['no']
                  date = request.form['date']
                  mo_62_upsd = request.form['mo_62_upsd']
                  mo_62_bpsd = request.form['mo_62_bpsd']
                  mo_87_upsd = request.form['mo_87_upsd']
                  mo_87_bpsd = request.form['mo_87_bpsd']
                  af_62_upsd = request.form['af_62_upsd']
                  af_62_bpsd = request.form['af_62_bpsd']
                  af_87_upsd = request.form['af_87_upsd']
                  af_87_bpsd = request.form['af_87_bpsd']
                  ev_62_upsd = request.form['ev_62_upsd']
                  ev_62_bpsd = request.form['ev_62_bpsd']
                  ev_87_upsd = request.form['ev_87_upsd']
                  ev_87_bpsd = request.form['ev_87_bpsd']
  
  
              with sql.connect(con_string) as con:
  
                  cur = con.cursor()
  
                  params = date, mo_62_upsd, mo_62_bpsd, mo_87_upsd, mo_87_bpsd, af_62_upsd, af_62_bpsd, af_87_upsd, af_87_bpsd, ev_62_upsd, ev_62_bpsd, ev_87_upsd, ev_87_bpsd, id
  
                  cur.execute("""UPDATE kudson_shift_daily_sell 
                                  SET date=?, mo_62_upsd = %s, mo_62_bpsd = %s, mo_87_upsd = %s, mo_87_bpsd = %s, af_62_upsd = %s, af_62_bpsd = %s, af_87_upsd = %s, af_87_bpsd = %s, ev_62_upsd = %s, ev_62_bpsd = %s, ev_87_upsd = %s, ev_87_bpsd = %s 
                                  WHERE id = %s""", params)
                  con.commit()
                  msg = "แก้ไขข้อมูลสำเร็จ"
  
  
              return render_template("kudson_edit.html", msg=msg)
  
          except Exception as e:
  
              return render_template("kudson_edit.html", msg=e)
  
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>
  
  <p>I'm sorry if code is not looking clean, I am a newbie at coding. </p>
  
  <p>Any help would be greatly appreciated!</p>