Specify the Django http status code and return.

What you want to solve

-Specify the Http status code in Django and return. -Ajax communication is performed with jQuery, and I want to force fail to be executed under specific conditions.

environment

・ Windows10 premium ・ VScode ・ JQuery

result

Ajax code omitted This is the processing when an appropriate character string is transmitted and the character "test`" is not included in the transmitted character string.

test.py


import HttpResponse

get_post = request.POST["testData"]

if not "test" in get_post:
    response = HttpResponse(status=500) #Specify 500 as the status code
    return response

reference

HTTP Status Code List

Recommended Posts

Specify the Django http status code and return.
[Python] Create a screen for HTTP status code 403/404/500 with Django
Check the HTTP status code response with the curl command (#Linux #Shell)
Python> datetime> Implementation> Specify the end date, interval, and start date, and return and display each interval.
Specify the view URL in your Django template
Specify the volume on linux and make a sound
Get the return code of the Python script from bat
Implement the Django user extension and register the attached information
[Django 2.2] Sort and get the value of the relation destination
Install django on python + anaconda and start the server