我正在尝试使用 Django 模板上传文件,但在 save_project
上我收到此回溯错误
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'E:\\forefront-v1.0\\media\\uploads\\temp\\10\\Video%20Sensor%20-%2013370_1798858.mp4' -> 'E:\\forefront-v1.0\\media/uploads/project-videos/Video%20Sensor%20-%2013370_1798858.mp4'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\forefront-v1.0\venv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "E:\forefront-v1.0\venv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "E:\forefront-v1.0\venv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "E:\forefront-v1.0\venv\lib\site-packages\django\views\generic\base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "E:\forefront-v1.0\venv\lib\site-packages\django\contrib\auth\mixins.py", line 52, in dispatch
return super().dispatch(request, *args, **kwargs)
File "E:\forefront-v1.0\venv\lib\site-packages\django\contrib\auth\mixins.py", line 109, in dispatch
return super().dispatch(request, *args, **kwargs)
File "E:\forefront-v1.0\venv\lib\site-packages\django\views\generic\base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "E:\forefront-v1.0\projects\views.py", line 2660, in post
project_id = self.save_project(
File "E:\forefront-v1.0\projects\views.py", line 2792, in save_project
video1 = self.upload_video_locally(video1) if video1 else None
File "E:\forefront-v1.0\projects\views.py", line 2872, in upload_video_locally
shutil.move(temp_file_path, saved_file_path)
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 826, in move
copy_function(src, real_dst)
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 435, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 264, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: 'E:\\forefront-v1.0\\media\\uploads\\temp\\10\\Video%20Sensor%20-%2013370_1798858.mp4'
[26/Jul/2021 13:12:27] "POST /upload/ HTTP/1.1" 500 23208
在项目 settings.py
# Upload
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
这是有问题的函数。在views.py
def save_project(
self,
image,
name,
excerpt,
body,
caption1,
caption2,
description1,
description2,
image1,
image2,
video,
video1,
video2,
authors_arr,
paperlink,
):
video = self.upload_video_locally(video) if video else None
video1 = self.upload_video_locally(video1) if video1 else None
video2 = self.upload_video_locally(video2) if video2 else None
if self.request.POST.get("previewed") or video is not None:
image = self.upload_file_locally(image, "banner", 1) if image else None
else:
image = self.upload_file_locally(image, "banner", 0) if image else None
if video1 is not None:
image1 = self.upload_file_locally(image1, "upm-img1", 1) if image1 else None
else:
image1 = self.upload_file_locally(image1, "upm-img1", 0) if image1 else None
if video2 is not None:
image2 = self.upload_file_locally(image2, "upm-img2", 1) if image2 else None
else:
image2 = self.upload_file_locally(image2, "upm-img2", 0) if image2 else None
# video2 = self.upload_video_locally(video2) if video1 else None
# image2 = self.upload_file_locally(image2, 'upm-img2', 0) if image2 else None
# image3 = self.upload_file_locally(image3, 'upm-img3', 0) if image3 else None
self.upload_file_to_s3() # upload all files to amazon s3
# self.upload_file_locally(image,name,True)
save_project = Project(
image=image,
name=name,
excerpt=excerpt,
body=body,
caption1=caption1,
caption2=caption2,
description1=description1,
description2=description2,
image1=image1,
image2=image2,
video=video,
video1=video1,
video2=video2,
paperLink=paperlink,
)
save_project.save()
# getting authors from request session
login_user_status = 0
for author in authors_arr:
if self.request.user.customuser.member.id == int(author["id"]):
login_user_status = 1
get_author = Member.objects.get(id=int(author["id"]))
save_project.authors.add(get_author)
if login_user_status == 0:
get_author = Member.objects.get(id=self.request.user.customuser.member.id)
save_project.authors.add(get_author)
return save_project.id
所以请帮我找到可能是问题的解决方案,我们可以解决这个问题。 我相信