python - Wagtail:创建自定义 API 端点

标签 python django wagtail

我创建了一个名为“Spotlights”的代码段,我想知道如何使用 Wagtail API 为代码段数据创建自定义端点。我最好的猜测是:

api_router.register_endpoint('Spotlights', BaseAPIEndpoint)

那里的第一个 arg 是建立端点的名称,还是引用某些东西?

最佳答案

我已经弄明白了:只是子类化 Wagtail 的 BaseAPIEndpoint。例如:

端点.py

from wagtail.api.v2.endpoints import BaseAPIEndpoint

class SpotlightsAPIEndpoint(BaseAPIEndpoint):
    ...
    model = Spotlight

api.py

from .endpoints import SpotlightsAPIEndpoint

api_router.register_endpoint('spotlights', SpotlightsAPIEndpoint)

此外,还有大量自定义方法。看看 Wagtail 存储库中的 endpoints.py 文件:https://github.com/wagtail/wagtail/blob/master/wagtail/api/v2/endpoints.py

关于python - Wagtail:创建自定义 API 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51713059/

相关文章:

django - TypeError:int()参数必须是字符串或数字,而不是Django中的 'AnonymousUser'

django - 即使有标记,pytest-django 也不允许访问数据库

python - ModelCluster ParentalManyToManyField 上的左外连接?

python - Wagtail 从字段创建自定义 StreamField block ?

python - 如何在 wagtail cms 字段中包含上下文变量?

python - 使用 scipy.linalg.blas.sgemm 时,numpy 点返回大数组的无效值

python - 如何防止Python中的舍入

python - 无法安装 prettytable

python - Azure Active Directory 错误。访问 token 来自错误的颁发者

javascript - jquery ui 自动完成结果不显示在 html 下拉列表中