我有源url domain.ex/dir/video.mp4
我有临时的url domain.ex/vlink/temp.mp4,需要将它“连接”到源domain.ex/dir/video.mp4。
同一领域。但是文件有不同的名字,video.mp4 != temp.mp4
我使用nginx提供源url。
location /dir/ {
alias /media/videos/;
}我现在的urls.py
path('vlink/<str:temp>', views.vlink, name='vlink'),view.py
def vlink(request, temp):
# drop extension mp4
s = temp.split('.')[0]
# I retrieve original file name
vid = TmpUrl.objects.filter(tmp_url = s).values('orig').first()
v = vid['orig']
the_url = '/dir/'+v+'.mp4'
return redirect(the_url)template.html
<video>
<source src="/vlink/{{vid}}.mp4" type="video/mp4">
</video>我不需要简单的重定向。我要隐藏来源网址。
我需要的是:当用户单击play时,浏览器会显示tmp url和play vid,而不会重定向到源代码。
怎么做?
发布于 2022-05-29 07:06:07
最后,我找到了解决办法。这是Nginx +X在Django的内部重定向。
views.py
def vlink(request, temp):
s = temp.split('.')[0]
vid = TmpUrl.objects.filter(tmp_url = s).values('orig').first()
v = vid['orig']
the_url = '/dir/'+v+'.mp4'
response = HttpResponse(status=200)
response['Content-Type'] = 'video/mp4'
response['X-Accel-Redirect'] = the_url
return responsenginx.conf
location /dir/ {
internal;
alias /media/videos/;
}https://stackoverflow.com/questions/72421123
复制相似问题