Django Controller确实下载了静态文件

时间:2018-07-16 15:06:03

标签: python django xml django-views

我的网络应用程序中有一个像这样的控制器:

   /**
     * Disconnects an established connection, or cancels a connection attempt
     * currently in progress.
     *
     * <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
     */
    public void disconnect() {
        if (DBG) Log.d(TAG, "cancelOpen() - device: " + mDevice.getAddress());
        if (mService == null || mClientIf == 0) return;

        try {
            mService.clientDisconnect(mClientIf, mDevice.getAddress());
        } catch (RemoteException e) {
            Log.e(TAG,"",e);
        }
    }

如何将我的代码更改为具有下载文件的功能,而不在Web浏览器中打开文件?

1 个答案:

答案 0 :(得分:0)

像这样吗?

def download_xml(request):
     xml = f.open(xml_file, "r")

     resp = HttpResponse(xml,
        mimetype = 'text/xml'
        )

    resp['Content-Disposition'] = 'attachment; filename=file.xml'
    return resp