为什么我得到一个带有tastypie POST请求的NoneType HttpRequest [英] Why am I getting a NoneType HttpRequest with tastypie POST request
问题描述
在开发过程中,我的本地主机工作正常,但是当我将其部署在服务器上时,我得到一个空的请求。
It works fine on my localhost during development but when I deployed it on the server I get an empty request.
class MyPinResource(Resource):
pin = fields.CharField(attribute='pin', null=True)
class Meta:
resource_name = 'my-pin'
authentication = ApiKeyAuthentication()
authorization = DjangoAuthorization()
always_return_data = True
include_resource_uri = False
object_class = ApiObject
allowed_methods = ['post']
def detail_uri_kwargs(self, bundle_or_obj):
if isinstance(bundle_or_obj, Bundle):
return { 'domain': bundle_or_obj.obj }
else:
return { 'domain': bundle_or_obj }
def obj_create(self, bundle, request=None, **kwargs):
site_id = None
if 'site_id' in request.GET and request.GET['site_id']:
site_id = request.GET['site_id']
else:
LOG.error('site_id is required!')
raise Exception
error_message:'NoneType'对象没有属性'GET'
"error_message": "'NoneType' object has no attribute 'GET'"
AttributeError: NoneType'对象没有属性'GET'
AttributeError: 'NoneType' object has no attribute 'GET'
当有请求request.GET
This error is inside obj_create when there is a call to request.GET
可能是错的?是否有空请求?
帮助将非常感激:)
What could be wrong? Is it possible to have an empty request? Help would be much appreciated :)
推荐答案
正如我在我的评论中写的,问题可能是版本,结帐这个github 问题。如果您使用0.9.12,您可以访问包
中的请求
。
As I wrote in my comment, the problem is probably the version, checkout this github issue. You can access the request
in the bundle
, if you're using 0.9.12.
这篇关于为什么我得到一个带有tastypie POST请求的NoneType HttpRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!