Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
Metadata
ID:python-django/http-response-with-json-dumps
Language: Python
Severity: Notice
Category: Best Practices
Description
Use JsonResponse instead of HttpResponse when attempting to send JSON data.
Non-Compliant Code Examples
importjsonfromdjango.httpimportHttpResponseresponse_data={}response_data['result']='error'response_data['message']='Some error message'returnHttpResponse(json.dumps(response_data))# use a JsonResponse to send JSON data