0

i have uploaded a video to django and it's all working fine .. but i need to render that video in the view.. django cant access it
any idea how to make django template see my uploaded files

modles.py :

class VideoData(models.Model): title = models.CharField(max_length=200) file = models.FileField(upload_to='vids' ) 

forms.py :

class UploadFileForm(forms.Form): title = forms.CharField(max_length=50) file = forms.FileField() 

and in template.html:

<video width="320" height="240" controls="controls"> <source src="vids/name.mov" type="video/mov" /> </video> 

it shows an empty video player.

am i doing anything wrong ?

please help

2 Answers 2

1

Assuming an instance of VideoData named vid is in the template's context, you should use:

<video width="320" height="240" controls="controls"> <source src="{{vid.file.url}}" type="video/mov" /> </video> 

To add the VideoData instance to the template's context, your view should look like this:

from django.shortcuts import render_to_response from models import VideoData def show_video(request): vid = VideoData.objects.get(id=1) # replace with correct query return render_to_response("template.html", {"vid":vid}) 
Sign up to request clarification or add additional context in comments.

Comments

1

Your video is uploaded media_root/vid directory(just check it on file system to make sure). so when you call it from template you should write your media template in front of your video image. (So your url could be /media/vids/name.mov) I also noticed that you are writing hardcoded video name here use something like following instead

<video width="320" height="240" controls="controls"> <source src="{{MEDIA_URL}}{{my_video_data.file}}" type="video/mov" /> </video> 

in order to use MEDIA_URL here you have to run your context variable through context processors checkout django.shortcuts.render method.

1 Comment

tried this and the path given is "C:\Users\moayyad\Desktop\bookfairp\..\bookfairp\vids\1_1.webm"<br>where it should be "C:\Users\moayyad\Desktop\bookfairp\vids\1_1.webm"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.