【发布时间】:2021-03-04 05:04:24
【问题描述】:
我正在尝试为必须使用 python open() 方法打开的一些 json 文件设置路径。阅读文档我注意到必须覆盖 django.core.files.storage 中类 Storage 的路径方法,但我不知道如何覆盖它,因为我不知道如何存储此路径。
我的文件是这样的
App
--index_backend
----json
-------some_json.json
----index.py
--views.py
manage.py
我是 Django 的新手,所以如果您需要查看更多代码,请告诉我尽可能多地上传。
更新 我想要实现的是在单击按钮时调用一个函数,该按钮向http://127.0.0.1:8000/App/getValues 发送一个请求,以便运行一个调用index.py 中另一个python 函数的python 函数。 index.py 里面的 some_json.json 是打开的,但是在运行 getValues 时,它会在 /App/getValues/ 处引发 FileNotFoundError,因为它在 /App/getValues/ 中寻找 some_json.json 而不是 /App/index_backend/json/
【问题讨论】:
-
您需要添加最少的代码。
标签: python-3.x django web django-models django-views