I have a problem trying to generate a CSV file with all registered users to export it.
def descargar_usuarios(request):
perfiles = Perfil.objects.all()
response = HttpResponse(content_type='application/csv')
with open('usuarios.csv','wb') as f:
writer = csv.writer(f)
columnas = []
writer.writerows(['usuario','nombre','apellido','correo','boutique'])
for p in perfiles:
columnas = [p.usuario.username,p.usuario.first_name,p.usuario.last_name,p.usuario.email,p.boutique]
writer.writerows(columnas)
writer.save(response)
return response
I try to write all the columns at once but I can not find the way.
Once you have it, I do not want to save it on the server, but download it from the browser.