Django using checkbox export csv -


i not know how download files have been check box; please me;

this views.py:

def export_selected_data(request):     if request.method == 'post':         _selected_action= request.post.getlist('_selected_action')         _selected_action =get_object_or_404(user, pk=user_id)      response = httpresponse(mimetype='application/vnd.ms-excel; charset="shift_jis"')     response['content-disposition'] = 'attachment; filename=file.csv'     writer = csv.writer(response)     obj_all=user.objects.all()     obj in obj_all:         row=[]         field in user._meta.fields:             row.append(unicode(getattr(obj,field.name)).encode("cp932"))         writer.writerow(row)     return response 

this index.html:

        <tr>             <td><input class="action-select" name="_selected_action" type="checkbox" value="{{ user_id }}"></td>             <td><a href="/index/get/{{ user.id }}/">{{ user.user_name }}</a></td>             <td>{{ user.company }}</td>             <td>{{ user.number }}</td>              <td>{{ user.phone }}</td>          </tr> 

errors in code:

  • this part doesn't make sense. looks you're trying list of users checkbox ticked out of blue line:

    _selected_action =get_object_or_404(user, pk=user_id)

  • mimetype csv text/csv

  • you don't write response object.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -