0

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> 
2
  • 2
    try <sourcesrc="{{lastvideo.videofile.url}}" type='video/mp4'> Commented Jan 19, 2022 at 6:44
  • I have uploaded two videos but showing only one video. what to do now. even i make changes in query to all instead of last, by doing this, it is only showing one video. Commented Jan 21, 2022 at 4:19

1 Answer 1

1

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> 
Sign up to request clarification or add additional context in comments.

3 Comments

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
I have uploaded two videos but showing only one video. How to solve this
You have to use for loop to call each videos.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.