Opened 9 years ago

Closed 9 years ago

Last modified 21 months ago

#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 Tim Graham, 9 years ago

Resolution: worksforme
Status: newclosed

Unfortunately due to history, the parameter is named different from the attribute, i.e. JsonResponse({'error':'Unauthorized access'}, status=401).

comment:2 by Ahmed Saidi, 9 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 Tim Graham, 9 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.

Note: See TracTickets for help on using tickets.
Back to Top