Uploading multiple files

my url.py looks like this


in views.py

class FileFieldView(FormView):
    form_class = FileFieldForm
    template_name = 'mainpage/multi.html'
    success_url = 'mainpage/mutli/'

    def post(self, request, *args, **kwargs):
        form_class = self.get_form_class()
        form = self.get_form(form_class)
        files = request.FILES.getlist('file_field')
        if form.is_valid():
               return self.form_valid(form)
            return self.form_invalid(form)

in forms.py

 class FileFieldForm(forms.Form):
       file_field = forms.FileField(widget=forms.ClearableFileInput(attrs={'multiple': True}))

in models.py

class many(models.Model):
    file_field= models.FileField()

and in multi.html

<form method="post" action="{% url 'multi_analysis' %}" enctype="multipart/form-data">
  {% csrf_token %}
<input type="file" name="file_field" multiple/>
<input type="submit" value="upload">

and the error is

TypeError: __init__() takes 1 positional argument but 2 were given

please help i am trying to figure it out for hours

Pls post you compete error screen

From the code you showed, everything seems to be in place

A little bit more of the stack trace would be helpful :+1:

in urls.py, maybe you lost as_view() function. does it like “FileFieldView.as_view()”?

in models.py try changing: class many(models.Model):
to: class Many(models.Model):

and in url.py change: path(‘mainpage/multi/’,views.FileFieldView,name=‘FileFieldView’),
to: path(‘mainpage/multi/’,views.FileFieldView.as_view(),name=‘FileFieldView’),