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 /'file'
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> <div class="file-path-wrapper"> <input class="file-path
Top comments (8)
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
and it was able to load the page
Thanks!
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
Hey! I'm having the same exact problem,
Can you share how you solved it?
Also how you iterate the tables from the csv file