请帮助我理解: 使用该代码,文件将被存储,一切顺利:
uploaded_file = request.FILES['file']
file_name = str(uploaded_file.name)
print ("filename = ", file_name)
#project_name = extract_project_name(uploaded_file)
#print ("project name = ", project_name)
found_entries = Project.objects.filter(name=file_name)
if(found_entries.count() == 0):
project = Project()
project.create(
file=uploaded_file,
)
但是如果我取消注释,我在数据库中创建对象时重新提取数据时会出错,因为它是None ... 有什么想法吗?
追溯:
Traceback (most recent call last):
File "<some path>/.local/lib/python3.5/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "<some path>/.local/lib/python3.5/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "<path here>/views.py", line 101, in upload_project_file
file=uploaded_file,
File "<path here>/project.py", line 33, in create
project.extract_project_infos()
File "<path here>/project.py", line 40, in extract_project_infos
Project_Data = json.loads(data)
File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)