When I am creating a HttpResponse object, should I pass it a integer for the status_code
attribute, or a string? I.e. HttpResponse('401 Client Error', status=401)
vs. HttpResponse('401 Client Error', status="401")
The documentation is a generic descriptor, that doesn't give the type.
HttpResponse.status_code
The HTTP status code for the response.
You should always pass an integer.
HttpResponse('401 Client Error', status=401)
As per the HTTP protocol:
The Status-Code element is a 3-digit integer result code of the attempt to understand and satisfy the request.
An integer, because the default value listed in the documentation is an integer. I.e. 200, instead of "200".
Building from Rahul Gupta's answer, an integer also because quote HTTP protocol,
The Status-Code element is a 3-digit integer result code of the attempt to understand and satisfy the request.
and because headers and metadata may be either strings or integers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With