django - 从 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)
```
解决方案
推荐阅读
- javascript - 使用带有引导选项卡的 Muuri Javascript 库 - 除非调整页面大小,否则不会展开?
- java - Java:键-键-值结构的内存高效存储-嵌套映射/键-值对
- ffmpeg - 运行时错误:中止(OOM)。使用 -s ASSERTIONS=1 构建以获取更多信息
- python - 给定地址的本地日期时间
- php - 即使值确实存在,in_array() 也不起作用
- android - 将 build compileSdkVersion 升级到 30 后无法确定是否安装了应用
- python - Python-我需要我的程序来计算掷出 2 个骰子的每个结果发生了多少次。(2-12 是可能的结果)
- apache-spark - 使用 Dask 和 pyarrow-dataset 引擎读取 Spark 编写的分区 parquet 数据集
- python - 在 2 个字符串之间更改 int
- javascript - 如何在 Xamarin 中使用 AI 模型