<https://lh6.googleusercontent.com/-dcfzdNsosAo/UzvfolMkv_I/AAAAAAAAAEk/9VN36S8Cdes/s1600/%E5%86%99%E7%9C%9F.JPG>
2014年4月2日水曜日 18時53分53秒 UTC+9 Choro H: > > > Thank you very much. > For example, i want to export only checked of a lot of information, > solike the following image: > > > > 2014年4月2日水曜日 11時22分55秒 UTC+9 somecallitblues: >> >> There are a few ways in which you can do this. One of them is to add some >> javascript to your code that will listen to onclick and check if your input >> button is selected. If it is it will submit the form that initiates your >> download. You can also do an Ajax post. Another way would be to create a >> link to that view. I don't understand why it needs to be checkbox if it's >> not a part of the form the user is submitting. >> >> >> On 2 April 2014 12:21, Choro H <[email protected]> wrote: >> >>> Sorry you all, >>> >>> so,i want to export csv from database that is only when checked >>> >>> >>> 2014年4月1日火曜日 13時22分31秒 UTC+9 Choro H: >>> >>>> Thank you very much! >>>> I'm Sorry, i'm missing write comments, >>>> I want to do download have been checboxd file from html, then i write >>>> to views.py this code, so i don't know how do write ! >>>> Please help me! >>>> this is my right code: >>>> def export_selected_data(request): >>>> # if request.method == 'POST': >>>> # _selected_action = request.POST.getlist("_ >>>> selected_action") >>>> >>>> response = HttpResponse(mimetype='application/vnd.ms-excel; >>>> charset="Shift_JIS"') >>>> response['Content-Disposition'] = 'attachment; filename=file.csv' >>>> writer = csv.writer(response) >>>> if request.method == 'POST': >>>> _selected_action = request.POST.getlist("_selected_action") >>>> >>>> _selected_action = User.objects.all() >>>> for obj in _selected_action: >>>> row=[] >>>> for field in User._meta.fields: >>>> row.append(unicode(getattr(obj,field.name)).encode(" >>>> cp932")) >>>> writer.writerow(row) >>>> return response >>>> This is my html: >>>> >>>> <form name="myForm" method="POST"> >>>> <select name="myMenu" onchange="myGo()"> >>>> <option value="/articles/export_selected_data" >selected_export >>>> </select> >>>> </form> >>>> <table > >>>> <thead> >>>> <tr> >>>> <th>Check</th> >>>> <th>名前</th> >>>> <th>会社名</th> >>>> <th>法人電話</th> >>>> </tr> >>>> </thead> >>>> <tbody> >>>> {% if articles.count > 0 %} >>>> {% for user in articles %} >>>> <tr> >>>> <td ><input class="action-select" name="_selected_action" id >>>> ="_selected_action" type="checkbox" value="{{user.id }}" type="submit" >>>> class="button"></td> >>>> <td ><a href="/articles/get/{{ user.id }}/">{{ user.user_name >>>> }}</a></td> >>>> <td >{{ user.company }}</td> >>>> <td >{{ user.number }}</td> >>>> </tr> >>>> {% endfor %} >>>> </tbody> >>>> </table> >>>> {% else %} >>>> <p>None</p> >>>> {% endif %} >>>> >>>> 2014年4月1日火曜日 12時47分08秒 UTC+9 Camilo Torres: >>>>> >>>>> Hello, >>>>> >>>>> You should start with the basics: >>>>> https://docs.djangoproject.com/en/1.6/topics/http/file-uploads/ >>>>> >>>>> You are using request.FILES and that is for file upload, no file >>>>> download. To upload a file to the server, you must have a <input >>>>> type="file" ...> in your template, which you don't have. >>>>> >>>>> To download files from the server to the browser (to the user >>>>> computer), you should do: >>>>> https://docs.djangoproject.com/en/1.6/ref/contrib/staticfiles/ >>>>> or, if the user uploaded the content: >>>>> https://docs.djangoproject.com/en/1.6/topics/files/ >>>>> >>>>> Hope this put you in the right direction. >>>>> >>>>> Camilo >>>>> >>>>> On Monday, March 31, 2014 1:31:24 AM UTC-4:30, Choro H wrote: >>>>>> >>>>>> Hello, >>>>>> >>>>>> i wan to do download file of a checkbox ; >>>>>> Please help me >>>>>> >>>>>> this is my viewspy: >>>>>> >>>>>> def export_selected_dataqq(request): >>>>>> if request.method == 'POST': >>>>>> _selected_action = request.FILES("_selected_action") >>>>>> >>>>>> response = HttpResponse(mimetype='application/vnd.ms-excel; >>>>>> charset="Shift_JIS"') >>>>>> response['Content-Disposition'] = 'attachment; filename=file.csv' >>>>>> writer = csv.writer(response) >>>>>> _selected_action = [] >>>>>> writer.writerow(_selected_action) >>>>>> >>>>>> for obj in _selected_action: >>>>>> >>>>>> row=[] >>>>>> for field in User._meta.fields: >>>>>> row.append(unicode(getattr(obj,field.name)).encode(" >>>>>> cp932")) >>>>>> writer.writerow(row) >>>>>> return response >>>>>> >>>>>> this is mmy html: >>>>>> >>>>>> <table > >>>>>> <thead> >>>>>> <tr> >>>>>> <th>Check</th> >>>>>> <th>名前</th> >>>>>> <th>会社名</th> >>>>>> <th>法人電話</th> >>>>>> </tr> >>>>>> </thead> >>>>>> <tbody> >>>>>> {% if articles.count > 0 %} >>>>>> {% for user in articles %} >>>>>> <tr> >>>>>> <td ><input class="action-select" name="_selected_action" id >>>>>> ="_selected_action" type="checkbox" value="{{user.id }}" >>>>>> type="submit" class="button"></td> >>>>>> <td ><a href="/articles/get/{{ user.id }}/">{{ >>>>>> user.user_name }}</a></td> >>>>>> <td >{{ user.company }}</td> >>>>>> <td >{{ user.number }}</td> >>>>>> </tr> >>>>>> {% endfor %} >>>>>> >>>>>> </tbody> >>>>>> </table> >>>>>> </form> >>>>>> {% else %} >>>>>> <p>None</p> >>>>>> {% endif %} >>>>>> >>>>> >>>> >>>> 2014年4月1日火曜日 12時47分08秒 UTC+9 Camilo Torres: >>>>> >>>>> Hello, >>>>> >>>>> You should start with the basics: >>>>> https://docs.djangoproject.com/en/1.6/topics/http/file-uploads/ >>>>> >>>>> You are using request.FILES and that is for file upload, no file >>>>> download. To upload a file to the server, you must have a <input >>>>> type="file" ...> in your template, which you don't have. >>>>> >>>>> To download files from the server to the browser (to the user >>>>> computer), you should do: >>>>> https://docs.djangoproject.com/en/1.6/ref/contrib/staticfiles/ >>>>> or, if the user uploaded the content: >>>>> https://docs.djangoproject.com/en/1.6/topics/files/ >>>>> >>>>> Hope this put you in the right direction. >>>>> >>>>> Camilo >>>>> >>>>> On Monday, March 31, 2014 1:31:24 AM UTC-4:30, Choro H wrote: >>>>>> >>>>>> Hello, >>>>>> >>>>>> i wan to do download file of a checkbox ; >>>>>> Please help me >>>>>> >>>>>> this is my viewspy: >>>>>> >>>>>> def export_selected_dataqq(request): >>>>>> if request.method == 'POST': >>>>>> _selected_action = request.FILES("_selected_action") >>>>>> >>>>>> response = HttpResponse(mimetype='application/vnd.ms-excel; >>>>>> charset="Shift_JIS"') >>>>>> response['Content-Disposition'] = 'attachment; filename=file.csv' >>>>>> writer = csv.writer(response) >>>>>> _selected_action = [] >>>>>> writer.writerow(_selected_action) >>>>>> >>>>>> for obj in _selected_action: >>>>>> >>>>>> row=[] >>>>>> for field in User._meta.fields: >>>>>> row.append(unicode(getattr(obj,field.name)).encode(" >>>>>> cp932")) >>>>>> writer.writerow(row) >>>>>> return response >>>>>> >>>>>> this is mmy html: >>>>>> >>>>>> <table > >>>>>> <thead> >>>>>> <tr> >>>>>> <th>Check</th> >>>>>> <th>名前</th> >>>>>> <th>会社名</th> >>>>>> <th>法人電話</th> >>>>>> </tr> >>>>>> </thead> >>>>>> <tbody> >>>>>> {% if articles.count > 0 %} >>>>>> {% for user in articles %} >>>>>> <tr> >>>>>> <td ><input class="action-select" name="_selected_action" id >>>>>> ="_selected_action" type="checkbox" value="{{user.id }}" >>>>>> type="submit" class="button"></td> >>>>>> <td ><a href="/articles/get/{{ user.id }}/">{{ >>>>>> user.user_name }}</a></td> >>>>>> <td >{{ user.company }}</td> >>>>>> <td >{{ user.number }}</td> >>>>>> </tr> >>>>>> {% endfor %} >>>>>> >>>>>> </tbody> >>>>>> </table> >>>>>> </form> >>>>>> {% else %} >>>>>> <p>None</p> >>>>>> {% endif %} >>>>>> >>>>>> -- >>> 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 [email protected]. >>> To post to this group, send email to [email protected]. >>> Visit this group at http://groups.google.com/group/django-users. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/django-users/d15a22b7-bbd2-4193-9a1a-49139e4b0ee0%40googlegroups.com<https://groups.google.com/d/msgid/django-users/d15a22b7-bbd2-4193-9a1a-49139e4b0ee0%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/991dc4e5-f342-4793-8863-b94267e0fa15%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

