django - 在django项目中保存文件以加载文件的位置,FileNotFoundError
问题描述
我有带有机器学习模型的 some_file.pkl,我需要将它加载到我的 django 项目中。加载过程是正确的,因为它与另一个项目一起工作。但是 django 说:
FileNotFoundError:[Errno 2] 没有这样的文件或目录:'some_file.pkl'
pickle 文件的位置在 django-app 下,我认为这是错误的原因,但我无法在 Djano 框架中找到要加载的文件的正确位置,请帮助。
这是我的看法:
def home(request):
content = ''
if request.method == 'POST':
if request.POST.get('sms'):
content = request.POST.get('fakenews_textarea')
#Load the Model back from file
with open("FakeNews_Model.pkl", 'rb') as file:
Fake_News_Model = pickle.load(file)
#Load the Model back from file
tfidf_vectorizer = pickle.load(open("tfidf.pickle", "rb"))
return render(request,'web/home.html')
解决方案
推荐阅读
- c# - 在 SAP HANA Studio 中重命名架构
- c++ - 对于黑客等级中的“两个字符串”问题,我在三个测试用例中遇到分段错误。是什么原因?
- c++ - 为什么我的 while 函数没有终止?
- javascript - 来自 .env 项的链接在 Vue.js 中被销毁
- angular - Cytoscape.js 并在订阅中加载数据
- c# - 更新 c# 项目安装程序
- python - TypeError:“ReadFile”Op 的输入“文件名”的类型为 float32,与预期的字符串类型不匹配
- javascript - Babel 没有在 Expo 中转换 TypeScript
- typescript - webgl 项目中的打字稿配置。意外的标记:在 typescript lint 错误中标记类型时
- python-3.x - 如何从 Telethon 装饰器方法返回列表或变量