# CSV modifying app

**URL:** <https://forum.djangoproject.com/t/csv-modifying-app/11111>\
**Category:** Using Django\
**Created:** [December 20, 2021, 1:27pm UTC](https://forum.djangoproject.com/t/csv-modifying-app/11111 "2021-12-20T13:27:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sad\_man](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sad_man/32/3241_2.png) [@sad\_man](https://forum.djangoproject.com/u/sad_man)\
**Post date:** [December 20, 2021, 1:27pm UTC](https://forum.djangoproject.com/t/csv-modifying-app/11111/1 "2021-12-20T13:27:08Z")

</div>

Hi everyone!

Had a more general question. I want to make an app that you upload a .csv file to, then the app generates a new csv, then you download it.

What would be the best approach for this?

Would you recommend using models, or is there a simple way to use POST without models? I’ve had a look at the documentation but it is a bit beyond me. I’d appreciate any advice on the general approach you can give. Thanks

Sad man

---

<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:** [December 20, 2021, 1:52pm UTC](https://forum.djangoproject.com/t/csv-modifying-app/11111/2 "2021-12-20T13:52:04Z")

</div>

Are you going to want to keep a copy of the csv on the server? Or is it just a transient processing of data?

If the latter, then a model is definitely not necessary. See [File Uploads | Django documentation | Django](https://docs.djangoproject.com/en/4.0/topics/http/file-uploads/#file-uploads) to get started, and then read [Uploaded Files and Upload Handlers | Django documentation | Django](https://docs.djangoproject.com/en/4.0/ref/files/uploads/#module-django.core.files.uploadedfile).

Your view would display a form with a FileField. On submit, your view would accept a file, read it, generate the output file, and then (possibly) return a [FileResponse](https://docs.djangoproject.com/en/4.0/ref/request-response/#fileresponse-objects).

---

<div class="post-metadata">

**Author:** ![sad\_man](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sad_man/32/3241_2.png) [@sad\_man](https://forum.djangoproject.com/u/sad_man)\
**Post date:** [December 20, 2021, 4:19pm UTC](https://forum.djangoproject.com/t/csv-modifying-app/11111/3 "2021-12-20T16:19:15Z")

</div>

Hi @KenWhitesell ,

Thanks so much for your answer. It would be transient processing. Thanks for your help.

So I’ve been trying your suggestion. However, I have two problems. First, I can’t seem to select the file from the request.FILES. I keep getting a MultiValueDictKeyError.

Here are my files:

views.py

```auto
def formatter(request):
    form = ArrayCsvForm()
    return render(request, "lab/formatter.html", {'form':form})

def formatter_result(request):
    my_file = request.FILES['myfile']

```

forms.py

```auto
from django import forms 
from .models import ArrayCsv

class UploadFileForm(forms.Form):
    title = forms.CharField(max_length=50)
    file = forms.FileField()

```

formatter.html

```auto
{% extends 'lab/base.html' %}
{% load static %}
{% block content %}

<div class="resources-page">

    <form action="{% url 'lab:formatter_result' %}" method="POST" enctype="multipart/form-data" name='myfile' type='file'>
        {% csrf_token %}
        {{form.as_p}}
        <button type="submit" name='myfile' >Upload and Submit</button>
    </form>
</div>

{% endblock %}

```

formatter\_results.html

```auto
{% extends 'lab/base.html' %}
{% load static %}
{% block content %}

<div class="resources-page">

    <form action="{% url 'lab:formatter_result' %}" method="POST" enctype="multipart/form-data" name='myfile' type='file'>
        {% csrf_token %}
        {{form.as_p}}
        <button type="submit" >Upload and Submit</button>
    </form>
</div>

{% endblock %}

```

Second, when I get around it using this view instead, how can I use this file since it is in a InMemoryUploadedFile, and not a csv?

```auto
def formatter_result(request):

    for filename, file in request.FILES.items():
        name = request.FILES[filename]
        my_file = file

```

Sorry for the long question Mr Whitesell, but any help would be appreciated, I’m really struggling with this. Thanks again for your help so far.

---

<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:** [December 20, 2021, 5:11pm UTC](https://forum.djangoproject.com/t/csv-modifying-app/11111/4 "2021-12-20T17:11:55Z")

</div>

Your views here don’t match the patterns of code as shown in the docs I referenced.

I suggest you start simple by following the docs as closely as possible before changing the patterns being used in the code, until you get to the point where you’re understanding what’s going on.

---

<div class="post-metadata">

**Author:** ![sad\_man](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sad_man/32/3241_2.png) [@sad\_man](https://forum.djangoproject.com/u/sad_man)\
**Post date:** [December 20, 2021, 5:33pm UTC](https://forum.djangoproject.com/t/csv-modifying-app/11111/5 "2021-12-20T17:33:24Z")

</div>

Ok thank you @KenWhitesell
