小编use*_*807的帖子

Django无法访问raw_post_data

Django我遇到了一个奇怪的事情,这是我的views.py:

def api(request):
    return HttpResponse("%s %s" % (request.method,request.raw_post_data))
Run Code Online (Sandbox Code Playgroud)

现在我使用POSTMAN(谷歌浏览器的小应用程序)进行HTTP POST.

我将POSTMAN设置为在原始字段中使用'test'发出POST请求.

Django给我三个不同的东西(随机):

有时Django会在某个时候返回'GET',有时甚至没有:

AttributeError at /
'WSGIRequest' object has no attribute 'raw_post_data'
Request Method: GET
Request URL:    https://api.mywebsiteurl.com/
Django Version: 1.6.2
Exception Type: AttributeError
Exception Value:    
'WSGIRequest' object has no attribute 'raw_post_data'
Exception Location: /home/spice_dj/spice/views.py in api, line 17
Python Executable:  /usr/bin/python
Python Version: 2.7.3
Python Path:    
['/usr/local/lib/python2.7/dist-packages/South-0.8.4-py2.7.egg',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/home/spice_dj']
Server time:    Wed, 12 Mar 2014 22:51:11 -0400
Run Code Online (Sandbox Code Playgroud)
  1. 当我清楚地发出POST请求时,为什么Django会回复我'GET'?

  2. 为什么它会给我这个错误?

  3. 为什么它不会返回我在原始字段中设置的"测试"?

python django django-1.6

16
推荐指数
1
解决办法
1万
查看次数

标签 统计

django ×1

django-1.6 ×1

python ×1