Django Web Tool - upload, process, export

I’m in the early stages of Django and I believe I have the fundamentals down however I’m having trouble with my webapp I’m trying to develop. What I would like to do is have a user upload file, then it gets processed using pandas and then the users new file is exported and ready for download. I’ve tried a few things:

def welcome(request):
    return render(request, "website/welcome.html")

def process_file(file_handle):
    li = []
    df = pd.read_csv(
    df.columns = ["ID", "Status", "Time", "Date", "Call Letters", " ", " "]
    return df.to_csv()

def model_form_upload(request):
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)

        if form.is_valid():
            document =
            # call to the new method
            csv = process_file(document.document)
            response = HttpResponse(csv, content_type='text/csv')
            response['Content-Disposition'] = 'attachment; filename=result.csv'
            return response
        form = DocumentForm()
    return render(request, 'website/model_form_upload.html', {'form': form})

class Document(models.Model):
    document = models.FileField(upload_to='documents/')

class DocumentForm(resources.ModelResource):
    class Meta:
        model = Document


{% extends 'base.html' %}

{% block content %}
<form method="post" enctype="multipart/form-data">
    {% csrf_token %}
    {{ form.as_p }}
    <button type="submit">Upload</button>

<p><a href="{% url 'welcome' %}">Return to home</a></p>
{% endblock %}

When I click my upload button, it throws me an error

TypeError: init() takes 1 positional argument but 3 were given

If anyone is able to help me out or even point me in the direction of a good tutorial on what I’m trying to achieve, that would be greatly appreciated

Could you provide more information about the error?. You will have plenty of information in the Web Browser, you can copy and paste it here.

No problem! Here is the traceback error:


Request Method: POST
Request URL:

Django Version: 3.2.6
Python Version: 3.9.6
Installed Applications:
Installed Middleware:

Traceback (most recent call last):
  File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\", line 47, in inner
    response = get_response(request)
  File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\\Desktop\workspace\crm_web_tool\website\", line 36, in model_form_upload
    form = DocumentForm(request.POST, request.FILES)

Exception Type: TypeError at /model_form_upload
Exception Value: __init__() takes 1 positional argument but 3 were given

I’ve never worked with this 3rd-party library you’re using (django-import-export), but from what I can see in the docs, a “ModelResource” is not a form to be created from POST data.

This line doesn’t make sense to me in the context of how you have DocumentForm defined.