python datatype()_使用Ajax将数据发布到Flask时Python NoneTypeDataType

在尝试使用Ajax将数据发送到Flask应用时,作者遇到了500错误,具体为TypeError: list indices must be integers, not NoneType。问题源于尝试用NoneType的数据作为列表索引。在前端,数据发送正常,包括id和rubric字段。在后端,尝试获取请求参数id并转换为整数时出现问题,可能是由于id参数未在请求中找到,导致request.args.get返回None。" 126509566,13058881,Excel数据处理:公式与多表引用,"['数据分析', 'Excel']
摘要由CSDN通过智能技术生成

我想弄清楚如何将ajax数据发送到我的烧瓶控制器,如果没有ajax,只需查找:

这是我的html模板中的表单:

在我的视图.py,获取索引“id”并对其进行强制转换:

^{pr2}$

$(document).ready(function() {

$(".rubric").editable('{{ url_for('editskills') }}',{

submit: 'Ok',

cancel: 'Cancel',

tooltip : 'Clic to edit',

type : 'textarea',

name : 'rubric'

});

});

{{ row["rubric"] }}

作为回报,我得到500个错误

我不明白为什么控制器总是发回那个错误:TypeError: list indices must be integers, not NoneTypeDataType :

从web调试器中,我发送的数据似乎没问题:FormData :

rubric: datasubmitted

id: 0

那些字段只是字符串,不是吗?为什么python说它们是非类型数据类型?在

[编辑-1]

标题:Request URL:http://:5000/editskills

Request Method:POST

Status Code:500 INTERNAL SERVER ERROR

Request Headersview source

Accept:text/html, */*; q=0.01

Accept-Encoding:gzip,deflate,sdch

Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4

Connection:keep-alive

Content-Length:25

Content-Type:application/x-www-form-urlencoded; charset=UTF-8

Cookie:session=eyJsb2dnZWRfaW4iOnRydWV9.BcMSfg.j5SaVklwzSzTdttCciYL_9dqZNg

DNT:1

Host::5000

Origin:http://:5000

Referer:http://:5000/competences

User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36

X-Requested-With:XMLHttpRequest

Form Dataview sourceview URL encoded

rubric:1Réseaux

id:0

Response Headersview source

Connection:close

Content-Type:text/html; charset=utf-8

Date:Thu, 23 Jan 2014 20:52:19 GMT

Server:Werkzeug/0.9.4 Python/2.7.3

X-XSS-Protection:0

预览:File "/home/noa/virtualenv/folio/foliodev/portfolio/views.py", line 39, in editskills

v = liste[i]

TypeError: list indices must be integers, not NoneType

抱歉,我犯了个错误,有导致错误的代码:i = request.args.get("id", type=int)

v = liste[i]

如果我试试这个:i = int(request.args.get("id"))

它直接影响演员:i = int(request.args.get("id"))

TypeError: int() argument must be a string or a number, not 'NoneType'

这让我把重点放在为什么我发送的数据是“非类型”上

非常感谢您抽出时间。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值