5.11 JLL实习日志-实现download功能实现
来源:互联网 发布:西部数码域名备案代办 编辑:程序博客网 时间:2024/05/16 10:54
1.主要实现的功能
根据下拉框的选择,传到后台views 中去,实现对应的xls的下载
2.实现的步骤
<form class="form" action=''>这边的问题在于action=?我使用了js 动态加载的样子实现{% csrf_token %}总是忘记这个form的标记符号<fieldset><div class="row" style="margin:10px 10px 0px -5px;">{% for field in form %}{% if field.html_name in select_box %}上面的步骤中,传过来一个form然后里面的一个field.html_name的概念<div class="col-xs-4 col-md-4">{{ field }}<script type="text/javascript">setTimeout(function() {var field_id = "id_" + "{{ field.html_name }}";var a = document.getElementById(field_id);a.setAttribute("class","form-control");a.setAttribute("display","inline");}, 100);</script> </div>{{ field.error }}{% endif %}{% endfor %}<p><a id='a' href="" onclick="javascript: return submit_confirm();" style="margin-top:5px" type="button" class="btn btn-primary"><i class="icon-download"></i> {{ ui_setting.Download}}</a></p></div></fieldset></form>
3.对应的js写法
js 增加一个addEvenLister(‘change’,function)方法
把select里面的值传给后台去
<script type="text/javascript"> var activities = document.getElementById("id_choices"); activities.addEventListener("change", function(){ var option=activities.getElementsByTagName("option"); for(var i=0;i<option.length;++i) { if(option[i].selected) { document.getElementById("a").href="/property/download/"+option[i].text+'/' console.log(document.getElementById("a").href) } } }); </script>
4.对应的url这边的操作
url(r'^property/download/(P<choice_type>\w+)/$',views.export_datas),
5.后台实现对应的views 操作
这边的choice_type
def export_datas(request,choice_type): print choice_type atype = "custom" if operation_access(access_setting.download_operation_access_list, request): if request.method == "GET": # ?get dao choice_type ? if atype == "custom": choice_type_object = Property.objects.all() column_names = data_export_setting.property_form_standard return excel.make_response_from_query_sets( choice_type_object, column_names, 'xls', file_name=choice_type+"_test", ) else: message_for_add_result = "fail" return render_to_response('property/view.html',{'message_for_add_result': message_for_add_result}, context_instance = RequestContext(request)) else: return page_not_found(request) else: return page_not_found(request)
0 0
- 5.11 JLL实习日志-实现download功能实现
- 5.12 JLL实习日志-实现download功能实现
- 5.10 JLL实习日志-实现upload 功能实现
- 5.12 JLL实习日志-实现Anjular Js 功能实现
- 7.3-7.5 JLL实习日志-实现DropDownBox的功能
- 5.2JLL实习 import 功能的实现
- 6.22-6.27 JLL--实习日志--Ajax+js 端实现
- 5.1JEE实习 downLoad 功能的实现
- 5.3 JLL 实习日志
- 5.5 JLL 实习日志
- 5.9 JLL实习日志
- 5.27 JLL--实习日志--
- 6.5 JLL--实习日志
- 5.17 JLL实习日志-实现get方式过滤数据,表格形式展现在前端
- 7.6-7.7 JLL实习日志-AngularJs的实现+windows下连接数据库
- 6.16-6.19 JLL--实习日志--
- Download功能的实现
- 5.26 JLL--实习日志--Primary_Image+total_setting
- java提高篇(二四)-----HashSet
- OAuth 2.0
- caffe执行draw.py的错误汇总
- 编译结果中各段意义
- FILE结构体与文件描述符
- 5.11 JLL实习日志-实现download功能实现
- java Data、String、Long三种日期类型之间的相互转换,需要的拿去用
- eclipse 配置
- 详解JUC之锁——ReentrantLock类(03)
- C语言实现合并两个有序(从小到大)顺序表为一个顺序表
- 字符格式(gbk utf8等)
- 高德地图Android开发-环境配置
- 改变HTML5的canvas默认值
- java按照map的value排序