0
響應正在將文件內容返回給瀏覽器。但是,下載不會發生。下面是代碼:Django/Sencha - HTTPResponse文件下載不起作用
的Django:
file2 = open(os.path.join(filename), 'rb')
response = HttpResponse(FileWrapper(file2),content_type='application/force-download')
response['Content-Disposition'] = 'attachment; filename=test.c'
file2.close()
煎茶:
xtype: 'button',
text: 'Generate Code',
tooltip: 'Generate Code',
disabled: true,
itemId: 'generatecode',
listeners: {
click: {
fn: me.getController().onGenCodeClick,
scope: me.getController()
}
}
onGenCodeClick: function() {
var me = this,
view = me.getView();
url = www_paths.backendURL + 'main/test/';
Ext.Ajax.request({
url: www_paths.backendURL + 'main/gencode/',
method: 'GET',
success: function (response, opts) {
Ext.core.DomHelper.append(document.body, {
tag : 'iframe',
frameBorder : 0,
width : 0,
height : 0,
css : 'display:none;visibility:hidden;height:0px;',
src : url
});
},
});
在瀏覽器的調試,網絡標籤:
General:
Request Method:GET
Status Code:200 OK
Remote Address:127.0.0.1:8001
Referrer Policy:no-referrer-when-downgrade
Headers:
Access-Control-Allow-Origin:*
Allow:GET, HEAD, OPTIONS
Content-Disposition:attachment; filename="pm_config_target_pbs_ram.c"
Content-Encoding:gzip
Content-Length:19210
Content-Type:application/force-download
Date:Tue, 05 Sep 2017 19:12:29 GMT
Server:WSGIServer/0.2 CPython/3.4.0
Vary:Accept, Cookie, Accept-Encoding
X-Frame-Options:SAMEORIGIN
在響應和預覽, 我」看到要下載的文件的內容。
但是,不知道爲什麼我沒有看到文件下載。
這是我的整個代碼。我只是想在我的頁面中進行基本的下載工作。 file2 = open(r'c:\ dropbox \ test.txt','rb') response = HttpResponse(FileWrapper(file2),content_type ='application/force-download') response ['Content-Disposition'] ='附件; filename = test.c' file2.close() return response – aman0446
你應該嘗試刪除這個file2.close()然後讓我知道。 –
對不起,忘了提。我也嘗試過。還是一樣。 – aman0446