Dondariadmin (トーク | 投稿記録) (ページの作成:「== 目的 == * Ajaxリクエスト用のアクションなので、Ajaxリクエストの場合のみレスポンスしたい。 * たとえば、WebブラウザからURL...」) |
Dondariadmin (トーク | 投稿記録) 細 |
||
(同じ利用者による、間の2版が非表示) | |||
15行目: | 15行目: | ||
== コード == | == コード == | ||
− | * [https://gist.github.com/shinsaka/097800f6b4525538fe846a3fb1e0614b | + | * [https://gist.github.com/shinsaka/097800f6b4525538fe846a3fb1e0614b gist: shinsaka/ajax_required_decorator.py] |
== 具体的には == | == 具体的には == | ||
24行目: | 24行目: | ||
from django.http import HttpResponseBadRequest | from django.http import HttpResponseBadRequest | ||
+ | from utils.decorators import ajax_required | ||
@ajax_required(HttpResponseBadRequest()) | @ajax_required(HttpResponseBadRequest()) | ||
def index(request): | def index(request): | ||
− | + | # any code | |
== 確認 == | == 確認 == |
from django.http import HttpResponseBadRequest from utils.decorators import ajax_required @ajax_required(HttpResponseBadRequest()) def index(request): # any code
$ curl --head http://localhost:5000/app/index/ HTTP/1.1 200 OK ...
$ curl --head http://localhost:5000/app/index/ HTTP/1.1 400 Bad Request ...Tweet