2017-09-05 9 views
0

応答を働いていないHTTPResponseは、ファイルのダウンロードには、ブラウザにファイルの内容を返しています。しかし、filedownloadは起こっていません。ジャンゴ/煎茶 -

ジャンゴ:

  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 

、 i」はダウンロードするファイルの内容が表示されます。

しかし、私は、ファイルのダウンロードが表示されない理由はわかりません。

答えて

0

あなたはあなたの全体のビューのコードを提供する必要がありますが、私はこの問題は、あなたがあなたの応答を返す前に、あなたのファイルを閉じることが考えられていることと思います。

+0

これは私の全体のコードです。私はちょうど私のページの中で働く基本的なダウンロードをしたい。 レスポンス= HttpResponse(FileWrapper(file2)、content_type = 'application/force-download') レスポンス['Content-Disposition'] = '添付ファイル。ファイル名= test.c ' file2.close() 返信応答 – aman0446

+0

このfile2.close()を削除して、私に知らせてください。 –

+0

申し訳ありませんが、忘れてしまいました。私もそれを試みた。まだ同じ。 – aman0446

関連する問題