我创建了一个名为“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/