Uploading multiple files

(Saurabh Kapoor) #1

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

(Basil Jose) #2

Pls post you compete error screen

(Vitor Freitas) #3

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

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

(Kevin) #4

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