Home > Mobile >  Django return custom HTTP message
Django return custom HTTP message

Time:09-21

I'm trying to be compatible with an app-side bug(). I want to return a response with custom HTTP message For example, I get HTTP/1.1 429 TOO_MANY_REQUESTS now, I want get HTTP/1.1 429 CUSTOM_MESSAGE Howerver, I can get only h2 200

CodePudding user response:

Django has HttpResponse objects to build custom responses.

The following should do the trick:

from django.http import HttpResponse

response = HttpResponse("CUSTOM MESSAGE", status=429, headers={"CUSTOM_MESSAGE": "..."})

see: https://docs.djangoproject.com/en/4.1/ref/request-response/#id4

CodePudding user response:

Updating HttpResponse.reason_phrase work for me, but HTTP/2.0 message will not show reason phrase, I could only find it in HTTP/1.1 message

see: https://docs.djangoproject.com/en/4.1/ref/request-response/#django.http.HttpResponse.reason_phrase

  • Related