[英]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
软件包,则会出现此错误。
pip freeze
pysendfile
安装django-sendfile
,请运行: pip uninstall pysendfile
和pip install django-sendfile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.