SOLVED: django raises MultiValueDictKeyError at / 'file'

highcenburg profile image Vicente G. Reyes Updated on ・1 min read

I'm trying to create a view for uploading a .csv file and parsing it on the template but it's returning a

MultiValueDictKeyError at /


The template has

<form method="POST" enctype="multipart/form-data">{% csrf_token %}
<div class="file-field input-field">
<div class="btn">
<span>Upload a CSV FILE</span>
<input type="file" name="file">
<div class="file-path-wrapper">
 <input class="file-path


markdown guide

In your view
def data_upload(request):
template = "home.html"
# add debugger here and check your params by which name your form #sending file .
csv_file = request.FILES['file'] # here you not getting name of file

you can do this also , i don't know it will solve this or not
Upload a CSV FILE
# change name from "file" to something #else like "csv_file"


I'll try this. I'm on another project so I'll let you know in a few hours if it worked or not. Thanks Mahendra!


yup , let me knoe if it work. if not let me know how you solved it ..-

I added

if request.method == 'GET':
return render(request, template)

and it was able to load the page


ok , but does csv file uploaded? In your form you sending POST request , then why if request.method == 'GET' returning true????

Yes, it went inside the admin through the models.py

the next problem is to iterate the tables from the csv file