我想写一个简单的瓶应用程序,我使用Postgresql作为数据库。我试图更新按钮,单击表行,但它给我下面的错误sqlalchemy.exc.DataError在Postgresql执行更新查询
DataError: (psycopg2.DataError) invalid input syntax for integer: "125/" LINE 1: ...ATE tasks SET taskname='IamUpdated' WHERE tasks.uid = '125/'^[SQL: 'UPDATE tasks SET taskname=%(taskname)s WHERE tasks.uid = %(uid_1)s'] [parameters: {'taskname': 'IamUpdated', 'uid_1': u'125/'}]
我不知道这是否是加入“/”结尾的毛刺或者它应该是这样的?或者那是造成错误的原因。 请帮助。
以下是我的瓶Python代码
edituser = request.form.getlist('editId')
if edituser:
for e in edituser:
User.query.filter_by(uid=e).update(dict(taskname="IamUpdated"))
db.session.commit()
return render_template("index.html",User=User.query.all())
以下是我的HTML代码
<form action="" method="POST">
<div ng-controller="myctrl" >
<table>
<caption> Todo List</caption>
<thead>
<tr>
<td>
<input type="text" name="text">
<input type="submit" value="Add Task" >
</td><td>
Search :<input type="text">
</td>
</tr>
<tr>
<th>Task Id</th>
<th>Task</th>
</tr>
</thead>
<tbody>
{% for user in User %}
<tr>
<td> {{ user.uid }} </td>
<td >{{ user.taskname }}
<input type="image" class="deleteImg" src="static/img/trash_can.png" height="15px" width="18px" name="removeId" value={{user.uid}} />
<input type="image" src="static/img/editbtn.svg" height="15px" width="18px" name="editId" value={{user.uid}}/>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<script>
var app = angular.module("app", ['xeditable']);
app.controller('myctrl', function($scope) {
$scope.myname="Howdy";
});
app.config(function($interpolateProvider) {
$interpolateProvider.startSymbol('//').endSymbol('//');
});
app.run(function(editableOptions) {
editableOptions.theme = 'bs3'; // bootstrap3 theme. Can be also 'bs2', 'default'
});
</script>
</form>
</body>
我们需要看看editId来自哪里。我怀疑你的模板有错误。 – Shadow
@shadow请检查我添加了HTML代码 – Prasanna