简体   繁体   English

使用视域资源

[英]Using tastypie resource in view

Im using the resource in my view. 我在我看来使用资源。 Whenever there are errors, they will be returned in immediatehttpresponse and its a httpbadrequest object. 每当有错误时,它们都将以即时httpresponse及其httpbadrequest对象返回。 When I do r.response I could see the contents which is in xml form, but I couldnt retreive the status code. 当我执行r.response时,我可以看到xml形式的内容,但是我无法获取状态码。 How to handle the errro response? 如何处理错误响应?

except ImmediateHttpResponse, r:
    print r.response

In case of HttpBadRequest the status code is always 400 (tastypie.http at line 41): 如果是HttpBadRequest,则状态码始终为400(tastypie.http位于第41行):

class HttpBadRequest(HttpResponse):
    status_code = 400

Also: 也:

r.status_code 

should give it to you. 应该给你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM