sriram anush
sriram anush

Reputation: 115

passing video_url to html template in django

I am trying to dispaly video in my html page by passing url as dict to template in django view named as succes

def success(request):
    url_video="/media/video1.mp4"

    return render(request,"payment/success.html",{"url_video":url_video})

my template code is all clear it has no errors i am getting this error on command prompt

Not Found: /succes/media/video1.mp4

I don't understand why i get success/ in front of url i have passed.The video file is in media/video1.mp4 location but it is not getting displayed.let me know any changes i need to make.thanks

EDIT:

TEMPLATE:

<!DOCTYPE html> 
<html> 
<head> 
<style> #myHeader { background-color: lightblue; color: black; padding: 40px; text-align: center; } 
</style> 
</head> 
<meta name="viewport" content="width=device-width"> 
<body> 
<h1 id="myHeader">"{{ url_video}}"</h1> <br> 

<video width=""height=""controls> 
    <source src="{{ url_video}}" type="video/mp4"> 
</video> 
</body> 
</html>

Upvotes: 1

Views: 548

Answers (1)

GAEfan
GAEfan

Reputation: 11370

Sounds like a relative path problem. Make sure you have:

url_video="/media/video1.mp4"

and not

url_video="media/video1.mp4"

Without the leading slash, it will try to find in directory of current url

Upvotes: 2

Related Questions