【发布时间】:2020-03-01 12:51:26
【问题描述】:
我在 django 中使用 apache2 服务器午餐了一个简单的视频下载器应用程序。我尝试使用 Path = os.path.expanduser("~") + "/Downloads/" 访问用户本地下载目录。但是每当有人尝试下载视频时,它会在服务器文件夹中下载,即 /home/SERVER USER NAME/Download,但不是用户下载目录.如何让它在用户本地下载目录中下载?
views.py
def download(request):
MusicPath = os.path.expanduser("~") + "/Downloads/"
if request.method == 'GET':
context = {
'videos_1080': PY.streams.get_by_itag('137'),
'videos_720': PY.streams.get_by_itag('22'),
'videos_normal': PY.streams.filter(progressive=True, subtype='mp4').first()
}
return render(request, "youtube/download.html",context)
if request.method == 'POST':
videos = PY.streams.filter(progressive=True, subtype='mp4').first()
videos.download(MusicPath)
messages.success(request, 'Video has been successfully downloaded !')
return redirect('home')
return render(request, "youtube/download.html", {"title": PY.title, "id": PY.video_id, 'views': PY.views})
此代码只是给出基本实现的示例
【问题讨论】:
-
@PedroLobito 请查看它
-
您的代码与您的问题不符。
Path = os.path.expanduser("~") + "/Downloads/",无处可寻。 -
只是打字错误。试着理解