lundi 19 janvier 2015

Embedding local video using Django

I'm using Django to create a webpage which displays a videoclip which will be created by the visitor her/himself. The following is my code:



from django.shortcuts import render
from django.http import HttpResponse
from django import forms
import numpy as np
from math import e
from matplotlib import pyplot as plt
from matplotlib import animation
from wsgiref.util import FileWrapper

class NumForm(forms.Form):
n1 = forms.FloatField(label = 'Slope_Upper')
n2 = forms.FloatField(label = 'Slope_Lower')

fig = plt.figure()
ax = plt.axes(xlim=(-3, 3), ylim=(0, 1))
ax.grid()
line, = ax.plot([], [], lw=2)

def psych(x,y,z):
return 1/(1+e**(-1*y*(x-z)))

def init():
line.set_data([], [])
return line,

def animate(i, lo, up):

x = np.linspace(-3,3,1000)
dif = up - lo
y = psych(x,.001*(up-lo)*i,0)
line.set_data(x, y)
return line,


def graph(request):
if request.method == 'POST':
form = NumForm(request.POST)
if form.is_valid():
sl_u = form.cleaned_data['n1']
sl_l = form.cleaned_data['n2']
anim = animation.FuncAnimation(fig, animate, init_func=init,
fargs=(sl_l, sl_u), frames=300, interval=20, blit=True)
anim.save(filename='video.mp4', fps=30, extra_args=['-vcodec', 'libx264'])
return render(request, 'plotting/video2.html')
else:
form = NumForm()

return render(request, 'plotting/retry.html', {'form': form})


And 'video2.html' is like this:



<html>
<body>
<embed src="file:///c:/plot/video.mp4">
</body>
</html>


When I run the local server and visit the webpage, I simply can't play the video. (The play button is not activated.) The question is: How could I play the video 'video.mp4', which is in my local folder, on the webpage I've created using Django?





Aucun commentaire:

Enregistrer un commentaire