LoginSignup
1
1

More than 3 years have passed since last update.

Django httpステータスコードを指定してreturnさせる。

Last updated at Posted at 2020-02-22

解決したいこと

・DjangoでHttpステータスコードを指定してreturnさせる。
・jQueryでAjax通信を行なっており、特定条件で強制的にfailを実行させたい。

環境

・Windows10 premium
・VScode
・jQuery

結果

Ajaxのコードは省略
仮に適当な文字列が送信され、送信された文字列内にテストという文字が含まれていない場合の処理とする。

test.py
import HttpResponse

get_post = request.POST["testData"]

if not "テスト" in get_post:
    response = HttpResponse(status=500) # ステータスコードに500を指定
    return response

参考

HTTPステータスコード一覧

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1