<meta charset="utf-8"/><h1>Cadastrar um novo material</h1><b>'Cadastre um novo material que pode ser usado para criar provas'</b><form action="{% url 'terminarcadastronovomaterial' %}" method="post" enctype="multipart/form-data" class="form-horizontal" charset='UTF-8'>{% csrf_token %} <label for="nome">Nome: </label> {% if nomematerialcadastrar %} <input id="nomematerial" type="text" name="nomematerial" value={{ nomematerialcadastrar }}> {% else %} <input id="nomematerial" type="text" name="nomematerial" value=""/> {% endif %} <div class="form-group"> <label for="arquivocsv" class="col-md-3 col-sm-3 col-xs-12 control-label">Arquivo csv: </label> <div class="col-md-8"> <input type="file" name="arquivocsv" id="arquivocsv" required="True" class="form-control"> </div> </div> <input type="submit" value="Cadastrar novo material"/></form>def terminarcadastronovomaterial(request): if request.method == 'POST': nomematerial = request.POST['nomematerial'] arquivo = request.FILES.get('arquivocsv') if arquivo.name.endswith('.csv'): file_data = arquivo.read().decode('utf-8') lines = file_data.split("\n") for line in lines: print("nova linha") fields = line.split(";") for field in fields: if ',' in field: distratores = field.split(",") print("distratores") for distrator in distratores: print(distrator) print("fim distratores") else: print(field) Hi,
in addition to what James said, it is unusual to write f.read().decode('utf-8'). Usually the result of f.read() is already decoded (unless you opened the file as a binary file, but you would normally not do that for a file containing text). It depends on how you opened the file, and the mechanics are different in Python 2 and Python 3.
BTW, I've been writing a series of posts on encodings, starting from https://djangodeployment.com/2017/06/19/encodings-part-1/. I'm interested in feedback.
Regards,
Antonis
Antonis Christofides http://djangodeployment.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2838894a-3a6b-4712-a53a-6b30ba53474f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.