首页 > 解决方案 > 从 celery 任务调用我的视图,这将访问第三方 API 并将数据保存到数据库中

问题描述

我想从 celery 任务中调用我的视图,该任务将访问 API 并将相应的数据保存到数据库中。

def test_task():
    # view_url = "domain/api/v1/id/connection"
    objects = Model.objects.all()
    for ob in objects:
        # get the id and for each id calll the test view
    




def testView(request):
    instance = self.self.get_object()
    #do the task

这是我的 celery 任务和视图,我想从该 celery 任务中访问

** 我的想法** 我想制作 url 并将 id 添加到 url,然后使用请求模块在该视图上发出请求。

例子 :

def test_task():
    objects = Model.objects.all()
    for ob in objects:
         view_url = "domain/api/v1/%s/connection" % ob.id
         request.get(view_url)
        ```

标签: djangodjango-rest-frameworkcelery

解决方案


推荐阅读