为什么一些 Django 类 和默认应用程序被称为 API?

Why some Django classes and default apps are called API?

我最近开始使用 Django 并遇到了一些实例,在文档中一些默认的 django classes 被称为 APIs。

一个这样的例子是在 link 上,其中模型 class 被称为 API.

这在某种程度上对我来说没有多大意义。我试过在网上搜索这个但没有帮助。模型 class 不是 class 和 API,还是两者都是?我完全没有研究过 Django Rest Framework,那么它会更有意义吗?

API(应用程序编程接口)是编程和库中的通用术语,它不是 Django 甚至 Web 框架特有的术语。一般来说,任何旨在供其他人使用的编程接口都是 API。这可以是模块、classes 等。通常,它们遵循某种设计模式或具有某种一致性元素。

如果您不熟悉术语,这可能会造成混淆,因为它与处理 REST/web API 的 Web 框架很接近,这可能是术语 API被使用。在此文档实例中 API 并不意味着网络 API.

requests 包有一个 API。 json 模块有一个 API。等等

Is the Model class not a class and an API, or can it be both?

它们当然不是排他性条款。 django.db.Model 当然是 class 并且有一个 API。最好说模型 class 一个 API 或者模型 class 是模型 API 的实现。

术语 API 有时可以与 User 界面 (UI) 对比使用。 REST 界面是编程界面 (API),网站前端是用户界面 (UI)。

用在一句话中:

“我喜欢模型 API,因为它简单干净,并且与整个 Django 生态系统相得益彰”

根据google,api的定义是:

a set of functions and procedures allowing the creation of applications that access the features or data of an operating system, application, or other service.

据了解,Django其实有很多api、Model、QuerySet、Manager等等