ไม่สามารถส่งค่าไปยัง database ได้
โพสต์แล้ว: 22/05/2019 6:21 pm
ผมทำการส่งข้อมูลไปยัง database แต่ขึ้น Error แบบนี้ครับ
ผลที่ได้
'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.
โคัด
ผลที่ได้
'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.
โคัด
โค้ด: เลือกทั้งหมด
#-*- coding=utf-8 -*-
from flask import Flask
from flask import render_template
from flask import request
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/', methods=['POST', 'GET'])
def addcode():
if request.method == 'POST':
name = request.form['filename']
code = request.form['rmlcode']
des = request.form['description']
try:
con = connect(host='127.0.0.1', database='miniproject', user='postgres', password=' ', port='5432')
cur = con.cursor()
sql = "insert into genpdf (filename, rmlcode, description) values ('%s','%s','%s')" % (name, code, des)
sql = sql.encode('utf-8')
try:
cur.execute(sql)
con.commit()
except:
con.rollback()
print('เพิ่มข้อมูล ผิดพลาด')
except :
print ('Error ' )
app.run(debug=True)