http://error codes的Json响应
django-json-error-response的Python项目详细描述
Json中的Django错误响应
django_json_error_response已准备好使用django库在自定义的JsonResponse中显示响应。在
新功能!在
- 比一般的JsonResopnse更易于使用响应。在
- 支持django-3+版本(自检)
您还可以:
使用:
from django_json_error_response.http import ( Http400Response, Http403Response, Http404Response, Http500Response, SuccessResponse, ErrorResponse )#code lines def my_view(request): if my_condition : #your codereturn SuccessResponse(message=my_message)#default status is 200 for this responseelse: return ErrorResponse(message=my_message, status=status_code)#status_code can be anything that you want to respond with. def my_custom_view(request): if condition: #your codereturn SuccessResponse(message=my_message)else: Http404Response(message=my_message)
对于ErrorResponse()
ErrorResponse take two arguments ~ message ~ status (for error except 404,403,400,500)
Exra信息
You can also pass json data insted of message or both at same time in every Resonse.
许可证
麻省理工学院
免费软件,见鬼!
- 项目
标签: