我想将csv文件导入到本地PC的数据库中,
DB:mysql
OS CentOS Apache
我有以下错误
module' object has no attribute `__getitem__`
def upload(request):
if request.method == 'POST':
filename = request.FILES["file1"]
content = request.FILES["file1"]
path = os.path.join("/tmp", csv)
file = open(path, "r+b")
file.reader(content)
reader = csv.reader( file)
for row in reader:
tmp = User.objects.create()
tmp.UserID = row[0]
tmp.user_name = row[1]
tmp.first_kana = row[2]
tmp.last_kana = row[3]
tmp.save()
file.close()
return HttpResponse("/memo/all")
args = {}
args.update(csrf(request))
args['upload'] = User.objects.all()
return render_to_response('importcsv.html', args)
below is importcsv.html:
{% extends "base.html" %}
{% block content %}
<div>
<form action="." method="POST" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="file1">
<input type="submit" value="import">
</form>
</div>
{% endblock %}