繁体   English   中英

Django sendfile与python 3.x vs 2.7

[英]django sendfile with python 3.x vs 2.7

当我将Django项目从python 2.7切换到Python 3.4时,出现以下代码错误。 在python 2.7中,一切正常。

from sendfile import sendfile
return sendfile(request, myfile, attachment=True, attachment_filename=filename)

如果我尝试在上面的代码上运行,我将得到以下错误。

    return sendfile(request, myfile, attachment=True, attachment_filename=filename)
TypeError: function takes exactly 4 arguments (2 given)

我浏览了一些python 3.4文档,并尝试了其他不同的选项。

尝试1:

        return sendfile(*(request, myfile), **{'attachment':True, 'attachment_filename':filename})
    TypeError: function takes exactly 4 arguments (2 given)

return sendfile(*(request, myfile), **{'attachment':True, 'attachment_filename':filename}

尝试2:

    return sendfile(request, myfile, True, filename)
TypeError: an integer is required (got type WSGIRequest)

我是python 3.4和django的新手。 请让我知道上面有什么问题吗?

注释推断出,如果您安装了pysendfile软件包而不是django-sendfile软件包,则会出现此错误。

  1. 如果有,请输入您的虚拟环境。
  2. 查看是否安装了哪些软件包: pip freeze
  3. 如果已安装pysendfile安装django-sendfile ,请运行: pip uninstall pysendfilepip install django-sendfile

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM