Пытаюсь сохранить загруженные файлы, но список файлов пуст, что не так?
upload
<form enctype="multipart/form-data" method="post">
{% csrf_token %}
{{ form.attachments }}
<button type="submit">Upload</button>
</form>
views
class FileFieldView(FormView):
print('join')
form_class = FileFieldForm
template_name = 'mainpage/upload.html' # Replace with your template.
success_url = '#' # Replace with your URL or reverse().
def post(self, request, *args, **kwargs):
print('Post')
form_class = self.get_form_class()
form = self.get_form(form_class)
files = request.FILES.getlist('file_field')
print(files)
if form.is_valid():
for f in files:
print('Save')
myfile = f
filesystem = FileSystemStorage()
filename = filesystem.save(myfile.name, myfile)
uploaded_file_url = fs.url(filename)
return self.form_valid(form)
else:
return self.form_invalid(form)
forms
from django import forms
class FileFieldForm(forms.Form):
attachments = forms.FileField(widget=forms.ClearableFileInput(attrs={'multiple': True}))
Подскажите где ошибка? Принтую files выводит [] пустой список