1
I have this following HTML, which is a form with an input for a file and Submit button:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document Classifier</title>
</head>
<body>
<div>
<h1> Document Classifier </h1>
</div>
<form name="form" method="POST">
{% csrf_token %}
<input type="file" name="file">
<button type="submit" class="btn btn-success">Classify</button>
</form>
I’m trying to save this file by calling the method Classify view:
from django.shortcuts import render
from .forms import DocumentForm
from .models import Document
# Create your views here.
def classify(request):
classified = False
print(request.FILES)
if request.method == "POST":
my_document_form = DocumentForm(request.POST, request.FILES)
if my_document_form.is_valid():
doc = Document()
doc.file = DocumentForm.cleaned_data["file"]
doc.save()
classified = True
else:
my_document_form = DocumentForm()
return render(request, 'documents/saved.html', locals())
return render(request, 'documents/base.html', {})
However, the request.FILE is coming empty, meaning the file is not coming. What can it be? I’ve tried several things. In the print I put inside the method, appears Multivaluedict: {} in the logs.
Okay, @Sidon. I’ll try. Thanks for the explanations.
– Antonio Braz Finizola