Manoj Tolagekar
Manoj Tolagekar

Reputation: 1970

Why video is not displaying when i click on upload

Here uploaded video is not displaying on template name video.html. It is storing video in media but it is not displaying on template. Tell me what to do. Please anyone can help me out.

views.py:

def showvideo(request):
    lastvideo= Video.objects.all()
    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>

Upvotes: 0

Views: 238

Answers (1)

Shada Bahassan
Shada Bahassan

Reputation: 36

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>

Upvotes: 1

Related Questions