【发布时间】:2019-10-28 15:48:48
【问题描述】:
DRF 教程包含以下关于 DRF 序列化程序与 Django 表单的内容:
The first thing we need to get started on our Web API is to provide a
way of serializing and deserializing the snippet instances into
representations such as json. We can do this by declaring serializers
that work very similar to Django's forms.
但据我所知,它没有说明表单和序列化程序之间的关系。
由于 DRF 不需要 Forms 在模板中呈现模型的能力,是否可以假设 Forms 在 DRF 中没有任何用途,并且序列化程序可以处理传统上通过表单完成的所有验证?
如果是这样,当我构建 API 时,我可以完全忘记模板和表单吗?
【问题讨论】:
-
在构建 REST API 时,您完全可以忘记表单和模板。内部序列化器 api 与您引用的内部 api 形式非常相似。
标签: django django-rest-framework django-forms