Модель вам нужна models.py
from django.db import models
class Video(models.Model):
name= models.CharField(max_length=500)
file= models.FileField(upload_to='videos/', null=True, verbose_name="")
Класс формы, который вам нужен forms.py
from .models import Video
class VideoForm(forms.ModelForm):
class Meta:
model= Video
fields= ["name", "file"]
inside views.py
from django.shortcuts import render
from .models import Video
from .forms import VideoForm
def showvideo(request):
firstvideo= Video.objects.last()
videofile= firstvideo.file.url
form= VideoForm(request.POST or None, request.FILES or None)
if form.is_valid():
form.save()
context= {'file_url': videofile,
'form': form
}
return render(request, 'videos.html', context)
И, наконец, ваш шаблон: videos.html
<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>
<video width='600' controls>
<source src='{{ file_url }}' type='video/mp4'>
File not found.
</video>
<br>
</p>
</body>