-
-
Save i5ar/3cb6c09e3405f389dfa2a74c503e3dd5 to your computer and use it in GitHub Desktop.
Django code to read uploaded CSV file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="{% url %}" method="post" enctype="multipart/form-data">{% csrf_token %} | |
<input type="file" name="csv_file" /> | |
<input type="submit" value="Upload" /> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index(request): | |
if request.POST and request.FILES: | |
csvfile = request.FILES['csv_file'] | |
dialect = csv.Sniffer().sniff(codecs.EncodedFile(csvfile, "utf-8").read(1024)) | |
csvfile.open() | |
reader = csv.reader(codecs.EncodedFile(csvfile, "utf-8"), delimiter=',', dialect=dialect) | |
return render(request, "index.html", locals()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment