升级到Django 1.3后清空request.POST [英] Empty request.POST after upgrade to Django 1.3

查看:133
本文介绍了升级到Django 1.3后清空request.POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在Django 1.2下正常工作但在Django 1.3下失败,因为request.POST为空,尽管表单数据已正确发布到服务器

The following code works fine under Django 1.2 but fails under Django 1.3 because request.POST is empty, although the form data is posted correctly to the server

def commit_form(request):
    logging.debug(str(datetime.datetime.now()) + ": commit data " + request.raw_post_data)
    purchase = Purchase.objects.get(transaction_id=request.POST['TransactionID']) #breaks here, request.POST is empty

    #other stuff...

    return HttpResponse("GOOD", mimetype="text/plain") 

为什么这不起作用,我不能看到这里有任何错误吗?

Why does this not work, I can't see any error here?

推荐答案

我记得有这样的问题,原来是访问 request.raw_post_data 阻止 request.POST dict随后填充post params。如果删除logging.debug行会发生什么?

I recall having a problem of this kind, it turned out that accessing request.raw_post_data prevented the request.POST dict from being subsequently populated with the post params. What happens if you remove the logging.debug line?

这篇关于升级到Django 1.3后清空request.POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆