0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DRFのviewで使えるHTTPメソッドを見分ける

Last updated at Posted at 2019-05-14

人が作ったAPIを利用するとき用、SWAGGER/OPEN APIが導入されてない環境用。

from rest_framework.generics import RetrieveUpdateDestroyAPIView #

viewのclassが何を継承してるかで見分けていく

クラス GET POST PUT PATCH DELETE
ListAPIView - - - -
RetrieveAPIView - - - -
CreateAPIView - - - -
DestroyAPIView - - - -
UpdateAPIView - - -
ListCreateAPIView - - -
RetrieveUpdateAPIView - -
RetrieveDestroyAPIView - - -
RetrieveUpdateDestroyAPIView -
# 例えばこれは、GET、POST両方OK
class HogeHogeList(ListCreateAPIView):

参考

Documentに書かれてるが早見表的ものが欲しかった

備考

viewが関数とデコレーターで実装されてる場合は、この辺は読んでて全然困らない

@action(methods=['POST'],detail=True)
def register_token(request, code):
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?