Почему видео не отображается, когда я нажимаю на загрузку
Здесь загруженное видео не отображается в шаблоне с именем video.html. Оно сохраняется в медиа, но не отображается в шаблоне. Подскажите, что делать? Пожалуйста, кто-нибудь может мне помочь.
views.py:
def showvideo(request):
lastvideo= Video.objects.last()
form= VideoForm(request.POST or None, request.FILES or None)
if form.is_valid():
form.save()
context= {'lastvideo': lastvideo,
'form': form
}
return render(request, 'master/video.html', context)
models.py:
class Video(models.Model):
name= models.CharField(max_length=500)
videofile= models.FileField(upload_to='videos/', null=True, verbose_name="")
def __str__(self):
return self.name + ": " + str(self.videofile)
forms.py:
class VideoForm(forms.ModelForm):
class Meta:
model= Video
fields= ["name", "videofile"]
templates: video.html:
<html>
<head>
<meta charset="UTF-8">
<title>Upload Videos</title>
</head>
<body>
<h1>Video Uploader</h1>
<form enctype="multipart/form-data" method="post" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Upload"/>
</form>
<br><br>
<video width='400' controls>
<source src='{{ MEDIA_URL }}{{ videofile }}' type='video/mp4'>
Your browser does not support the video tag.
</video>
<br><br>
</p>
</body>
<script>'undefined'=== typeof _trfq || (window._trfq = []);'undefined'=== typeof _trfd && (window._trfd=[]),_trfd.push({'tccl.baseHost':'secureserver.net'}),_trfd.push({'ap':'cpbh-mt'},{'server':'p3plmcpnl487010'},{'id':'8437534'}) // Monitoring performance to make your website faster. If you want to opt-out, please contact web hosting support.</script>
<script src='https://img1.wsimg.com/tcc/tcc_l.combined.1.0.6.min.js'></script>
</html>
views.py:
def showvideo(request):
lastvideo= Video.objects.all()
context= {'lastvideo': lastvideo }
return render(request, 'master/video.html', context)
templates: video.html:
<video width='400' controls>
<source src='{{ videofile.url }}' type='video/mp4'>
Your browser does not support the video tag.
</video>
</html>