Joh*_*cos 8 django django-forms django-rest-framework
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.
Run Code Online (Sandbox Code Playgroud)
但据我所知,它没有说明表单和序列化器之间的关系。
由于 DRF 不需要 Forms 在模板中呈现模型的能力,因此可以公平地假设 Forms 在 DRF 中没有用途,并且序列化器可以处理传统上使用表单完成的所有验证吗?
如果是这样,当我构建 API 时,我可以完全忘记模板和表单吗?
Django REST Framework用于创建发送XML
或JSON
.
Django Forms用于HTML
基于给定模型创建表单。
由于 API 的作用通常不涉及发送 HTML,因此不会使用 Django 表单。
归档时间: |
|
查看次数: |
1411 次 |
最近记录: |