Python 在Postgresql中执行更新查询时发生sqlalchemy.exc.DataError

Python 在Postgresql中执行更新查询时发生sqlalchemy.exc.DataError,python,postgresql,sqlalchemy,flask-sqlalchemy,Python,Postgresql,Sqlalchemy,Flask Sqlalchemy,我正在尝试编写一个简单的flask应用程序,其中使用Postgresql作为数据库。我试图在单击按钮时更新表行,但它给了我以下错误 <form action="" method="POST"> <div ng-controller="myctrl" > <table> <caption> Todo List</caption> <thead>

我正在尝试编写一个简单的flask应用程序,其中使用Postgresql作为数据库。我试图在单击按钮时更新表行,但它给了我以下错误

<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>
DataError:(psycopg2.DataError)整数的输入语法无效:“125/”第1行:…ATE任务集taskname='IamUpdated'WHERE tasks.uid='125/'^[SQL:'更新任务集taskname=%(taskname)s WHERE tasks.uid=%(uid_1)s'][参数:{taskname':'IamUpdated',uid_1':u'125/']

<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>
我不确定它是在结尾添加“/”作为一个小故障,还是应该是这样的?或者这就是导致错误的原因。 请帮忙

<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>
下面是我的flaskpython代码

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())
<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>
下面是我的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>

<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>

事項清單
搜索:
任务Id
任务
{用户%中的用户为%1}
{{user.uid}
{{user.taskname}
{%endfor%}
var app=angular.module(“app”,['xeditable']);
应用程序控制器('myctrl',函数($scope){
$scope.myname=“Howdy”;
});
app.config(函数($interpolateProvider){
$interpolateProvider.startSymbol('/').endSymbol('/');
});
应用程序运行(功能(可编辑选项){
editableOptions.theme='bs3';//bootstrap3主题。也可以是'bs2','default'
});

错误是因为我在输入标记的末尾有“/>”。这是不必要的。我已经移除了它,现在它工作正常。

您的问题似乎是这里的标签:

<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>
<input type="image" src="static/img/editbtn.svg"  height="15px" width="18px" name="editId" value={{user.uid}}/>
完成此操作后,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请检查我添加的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>