django-rest-framework - autogenerate form in browsable API?

前端 未结 3 1321
北荒
北荒 2021-01-04 10:19

Not sure if i\'m using the right vocabulary. In the browsable api that comes for free with django-rest-framework, I was wondering if there was a way to autogenerate a form s

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-04 10:49

    If you're using the generic class-based-views you'll get that for free. Try the live tutorial at http://restframework.herokuapp.com logging in as one of the users, so that you can create some snippets. eg user: 'max', password: 'max'.

    Any views subclassing GenericAPIView and setting a serializer_class will get that behavior, as REST framework can determine what the form should look like.

    For example:

    screenshot of form input

    (Note the form input at the bottom of the screen shot)

    If you're just working from APIView you'll get the generic content input (such as json), like the once you've included a screenshot of, which is also useful, but not quite as convenient as the forms.

提交回复
热议问题