伪代码
// data.id 数据ID
:href="'www.baidu.html?id='+data.id"
// 获取url参数 name 参数对象名称
get_query_string: function(name){
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return decodeURI(r[2]);
}
return null;
},
vue 写入文本
.then(response => {
this.data_down = response.data
var elink = document.createElement('a');
elink.download = "ceshi.txt"; // 写入的文件名
elink.style.display = 'none';
var blob = new Blob([this.data_down], {type: 'text/plain'});
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
document.body.removeChild(elink);
Django 返回文本内容
response = HttpResponse(content_type='APPLICATION/OCTET-STREAM')
response['Content-Disposition'] = 'attachment; filename=gatfile.txt'
if len(serializer.data) != 0:
for gatfile in serializer.data:
# Text file
if "server_id_data1_lan_ip" not in gatfile:
gatfile["server_id_data1_lan_ip"] = None
if "server_id_data2_lan_ip" not in gatfile:
gatfile["server_id_data2_lan_ip"] = None
response.write("""gatfile "%s" "%s" "%s" "%s" "%s" "%s" "%s" "%s" "%s" \n""" %
(gatfile["server_id_network_ip"], gatfile["server_id_name"], gatfile["areas_id"],
gatfile["name"], gatfile["server_id_sshport"], gatfile["server_id_server_version"],
gatfile["server_id_data1_lan_ip"], gatfile["server_id_data2_lan_ip"],
gatfile["run_time"]))
return response