在frappe框架中使用外部API创建多个docytpe文档

问题描述 投票:0回答:1

我是 frappe 框架的新手,过去一周一直在尝试使用它。 我想从一个 API 创建多个文档类型,该 API 从 GET 调用返回 json 对象列表。 我该怎么做,还可以帮助我在文件方面进行导航,因为我是新手 目前我一直在编辑.py文件

这是我写的代码

import frappe
from frappe.model.document import Document
import requests

class todolist(Document):
    # pass
    def new_document(self):
        doctype_name = "todo-list"
        json_data = (requests.get("https://jsonplaceholder.typicode.com/todos")).json()
        for json_object in json_data:
            new_doc = frappe.get_doc({
                "doctype": doctype_name,
                "id": json_object["id"],
                "title": json_object["title"],
                "completed": json_object["completed"],
            })
        
        new_doc.insert()

每当我运行此文件时,都会收到错误

ModuleNotFoundError: No module named 'frappe.model'

我想从外部 GET 请求将数据保存到我的文档类型中,但我在运行 frappe 时遇到问题。 从 github 安装了 Frappe-Docker ,创建了新的站点和应用程序,链接了两者,手动创建了一个文档类型,然后尝试编辑该 python 文件。

python orm erpnext frappe frappe-charts
1个回答
0
投票

可能是安装没正确完成,请检查frappe是否安装正确,并确保您使用的至少是frappe版本14 这是检查工作台版本的命令 长凳--版本 尝试:- 工作台更新 也尝试升级冰沙 尝试:- pip install --upgrade frappe

© www.soinside.com 2019 - 2024. All rights reserved.