接受JSON格式,解析他并具有访问数据的终点(Django)

发布于 2025-02-13 03:24:33 字数 492 浏览 0 评论 0原文

您好,我想问一下如何在Django中创建模型和API,该模型和API接受JSON格式,解析它,然后在某些端点中访问它。我想拥有[post] endpoint /import它将接受数据并解析它们,[get] /delets/< name_of_the_model>将从该记录列表中显示JSON文件基于模型的名称,最后/delet/< name_of_the_model>/< id>显示所有显示所有来自JSON文件的确切记录的数据。我认为我可以使用模型/模型来管理事情,但我无法弄清楚如何使用JSON实施它。感谢您的帮助。

PS:大约有8个具有属性的不同变量(不知道在JSON中调用它是如何称呼的),如果我为每个变量创建模型,我不确定是否正确执行此操作。这就是为什么我认为导入JSON是一件大事,但不知道该怎么做。

编辑:我已将REST框架安装到Django。也许那可能是道路,但仍然不知道如何正确地做。找不到任何地方。

Hello I want to ask how can I create models and API in Django that accepts JSON format, parsing it and then access it in some of the endpoints. I want to have [POST] endpoint /import which will accept the data and parse them, [GET] /detail/<name_of_the_model> will show list of records from the JSON file based on the name of the model and finally /detail/<name_of_the_model>/<id> which shows all the data for the exact record from the JSON file. I think I can manage things with the models/modelForms but I can't figure out how to implement it with JSON. Thanks for any help.

PS: There are like 8 different variables with attributes (don't know how is it called in JSON) and I'm not sure if I'm doing it right if I create model for each of the variables. That's why I think that import the JSON is such a big thing but don't know how to do it.

EDIT: I've installed REST Framework to Django. Maybe that could be the way, but still have no idea how to do it properly. Can't find it anywhere.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文