我正在尝试提交一个html表单来更新我的mysql数据库中的记录。我的代码是在python中,我已经尝试了一切,包括form.FieldStorage(),POST和GET方法,但没有什么是成功的。 我的python代码如下
@route('/update_artist_information/:numb', method='GET')
def update_artist_information(numb):
if request.GET.get('Update Information','').strip():
val1= request.GET.get('val1', '').strip()
val2 = request.GET.get('val2', '').strip()
val3 = request.GET.get('val3', '0').strip()
conn = pymysql.connect(host='localhost', port=3306, user='username', passwd='mypass', db='mydb')
c = conn.cursor()
c.execute("SET NAMES utf8")
query = "UPDATE tab1 SET val1 = '%s', val2 = '%s', val3 =%s WHERE ar_taut = '%s'" % (val1,val2,val3,numb)
c.execute(query)
conn.commit()
c.close()
return artists_show_all()
else:
conn = pymysql.connect(host='localhost', port=3306, user='username', passwd='mypass', db='mydb')
c = conn.cursor()
c.execute("SET NAMES utf8")
query = "SELECT val1, val2, val3 FROM tab1 WHERE numb = '%s'" %numb
c.execute(query)
cur_data = c.fetchone()
print (cur_data)
return template('Update_Artist_Information.html', old = cur_data, numb = numb)
我的html文件如下
<p><strong>Update Artist Information </strong></p>
<form action="/artists_show_all/{{numb}}"method="GET">
<table width="239" height="147" border="1">
<tr>
<td width="83">val1</td>
<td width="140"><input type="text" name="val1" id="val1" value=" {{old[0]}}" /></td>
</tr>
<tr>
<td>val2</td>
<td><input type="text" name="val2" id="val2" value="{{old[1]}}"/> </td>
</tr>
<tr>
<td>Birth Year</td>
<td><input type="text" name="val3" id="val3" value="{{old[2]}}" /></td>
</tr>
<tr>
<td><input type="submit" name="Update Information" id="Update Information" value="Update Information" /></td>
</tr>
</table>
</form>
我尝试更新后得到的错误是&#34;此页面不存在!&#34;。我检查了所有文件中的每一条路线,我找不到任何错误。我是网络新手申请aand python所以,如果你能帮助我,我将不胜感激。 提前致谢