# Django Web Tool - upload, process, export

**URL:** <https://forum.djangoproject.com/t/django-web-tool-upload-process-export/9512>\
**Category:** Using Django\
**Created:** [September 1, 2021, 4:07pm UTC](https://forum.djangoproject.com/t/django-web-tool-upload-process-export/9512 "2021-09-01T16:07:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rockeysc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/rockeysc/32/5702_2.png) [@rockeysc](https://forum.djangoproject.com/u/rockeysc)\
**Post date:** [September 1, 2021, 4:07pm UTC](https://forum.djangoproject.com/t/django-web-tool-upload-process-export/9512/1 "2021-09-01T16:07:12Z")

</div>

Hello,  
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:

views.py

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

def process_file(file_handle):
    li = []
    df = pd.read_csv(
        file_handle,
        index_col=None,
        header=None,
        error_bad_lines=False,
        sep=",",
        warn_bad_lines=False,
        encoding="latin-1",
    )
    df.columns = ["ID", "Status", "Time", "Date", "Call Letters", " ", " "]
    li.append(df)
    return df.to_csv()

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

        if form.is_valid():
            document = form.save()
            # 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
    else:
        form = DocumentForm()
    return render(request, 'website/model_form_upload.html', {'form': form})

```

models.py

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

```

resource.py

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

```

template

```auto
{% extends 'base.html' %}

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

<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

---

<div class="post-metadata">

**Author:** ![Rigo-Villalta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/rigo-villalta/32/5667_2.png) [@Rigo-Villalta](https://forum.djangoproject.com/u/Rigo-Villalta)\
**Post date:** [September 1, 2021, 5:33pm UTC](https://forum.djangoproject.com/t/django-web-tool-upload-process-export/9512/2 "2021-09-01T17:33:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rockeysc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/rockeysc/32/5702_2.png) [@rockeysc](https://forum.djangoproject.com/u/rockeysc)\
**Post date:** [September 1, 2021, 5:36pm UTC](https://forum.djangoproject.com/t/django-web-tool-upload-process-export/9512/3 "2021-09-01T17:36:23Z")

</div>

No problem! Here is the traceback error:

```auto
Environment:

Request Method: POST
Request URL: http://127.0.0.1:8000/model_form_upload

Django Version: 3.2.6
Python Version: 3.9.6
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'import_export',
 'website']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback (most recent call last):
  File "C:\Users\rock.sc\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\rock.sc\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\rock.sc\Desktop\workspace\crm_web_tool\website\views.py", 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

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [September 1, 2021, 8:32pm UTC](https://forum.djangoproject.com/t/django-web-tool-upload-process-export/9512/4 "2021-09-01T20:32:53Z")

</div>

> [@rockeysc](#):
>
> ```auto
> class DocumentForm(resources.ModelResource):
> class Meta:
> model = Document
> 
> ```

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.

> [@rockeysc](#):
>
> `form = DocumentForm(request.POST, request.FILES)`

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