【发布时间】:2018-07-26 11:35:30
【问题描述】:
我正在尝试构建一个GET 和POST 方法来获取和保存一些对象。
我有views.py这样的
class QuestionList(generics.ListAPIView):
queryset = Question.objects.all()
serializer_class = QuestionSerializer
class QuestionSave(generics.CreateAPIView):
queryset = Question.objects.all()
serializer_class = QuestionSerializer
然后我有 url conf,urls.py 像这样
urlpatterns = [
url(r'^questions/$',views.QuestionList.as_view())
]
据我了解,我们必须有一个泛型类,其中 CreateApiView 用于 POST 方法,ListApiView 用于GET 方法,所以我创建了这样的类。
我的问题是,我应该如何配置它们以便在 POST QuestionSave 将被调用并在 GET QuestionList 将被调用?
【问题讨论】:
-
为什么不
QuestionList(generics.ListAPIView, generics.CreateAPIView)?
标签: python django django-rest-framework django-views