#26262 closed New feature (worksforme)
Add HTTP response status code to JsonResponse
| Reported by: | Ahmed Saidi | Owned by: | nobody |
|---|---|---|---|
| Component: | HTTP handling | Version: | 1.9 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The JsonResponse class doesn't have/accept a status code, it would be helpful to add a status_code paramtere to this class, for example:
return JsonResponse({'error':'Unauthorized access'}, status_code=401)
Change History (3)
comment:1 by , 10 years ago
| Resolution: | → worksforme |
|---|---|
| Status: | new → closed |
comment:2 by , 10 years ago
Great, i didn't see that in the documentation of JsonResponse, is it missing or i didn't see it?
comment:4 by , 10 years ago
It could be more explicit I suppose. The docs say, "An HttpResponse subclass that helps to create a JSON-encoded response. It inherits most behavior from its superclass with a couple differences" and documentation for __init__() shows **kwargs in addition to the parameters that are specific for JSONResponse.
Unfortunately due to history, the parameter is named different from the attribute, i.e.
JsonResponse({'error':'Unauthorized access'}, status=401).