0

I am new to django. I have created application using it where user can see the videos of their undergoing subjects. I have uploaded multiple videos inside folder name uploadcbse and uploadncert which is present inside media directory. Now I want to display this video in html page but can't access it using {{Media_URL}}{{videofile}}. I am sure it's an error in mentioning path properly because other text fields have been displayed correctly.

1 Answers1

1

Here you go:

Set your media configs something like this inside 'settings.py':

#Set media path
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
MEDIA_URL = '/media/'

Lets say I have a modal called person with image filed like below:

class Person(models.Model):
    name = models.CharField(max_length = 30)
    photo = models.ImageField(upload_to = 'photos')

Now here upload_to path we are talking about is inside the MEDIA_ROOT folder. In my case a media folder will be created inside which photos folder will be created and our media here will be dumped.

So now in my template I do something like this:

<img src="{{ person.photo.url}} />

So in short, you got a field, use it like this:

src ={{ object.field.url}}

Hope that helps! Happy Coding!