我希望能够查看我上传的文件。我对自己所做的事情的掌握真的很差。
views.py
def upload_file(request):
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('learning_logs:topics'))
else:
form = DocumentForm()
return render(request, 'learning_logs/model_form_upload.html', {'form':form})
def file_preview(request):
videos = Document.objects.all()
context = {'videos':videos}
return render(request, 'learning_logs/video.html', context)
models.py
class Document(models.Model):
docfile = models.FileField(upload_to = 'documents/')
upload_at = models.DateTimeField(auto_now_add = True)
forms.py
class DocumentForm(forms.ModelForm):
class Meta:
model = Document
fields = ['docfile']
我已经上传了视频和图片。
将文件传递到HTML时,我只能看到上传的文件名。我无法单击链接来查看文件。
我想要一个实际的视频播放器来播放视频或查看图片。