Python Django页面未加载异常';字节';对象是不可调用的问题
我正在用Django下载文件。我已经在url.py和views.py中添加了路径,试图生成将加载文件和呈现页面的代码Python Django页面未加载异常';字节';对象是不可调用的问题,python,django,django-views,Python,Django,Django Views,我正在用Django下载文件。我已经在url.py和views.py中添加了路径,试图生成将加载文件和呈现页面的代码 def download(request): render(request, 'personal/home.html') # seems that it doesn't work filename = "C:/some_path/test_file.txt" wrapper = FileWrapper(open(filename)) respo
def download(request):
render(request, 'personal/home.html') # seems that it doesn't work
filename = "C:/some_path/test_file.txt"
wrapper = FileWrapper(open(filename))
response = HttpResponse(wrapper, content_type='text/plain')
response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(filename)
response['Content-Length'] = os.path.getsize(filename)
return response
结果我得到:
异常类型:TypeError
异常值:“字节”对象不可调用
有人能帮忙吗?删除此行:
render(request, 'personal/home.html')
谢谢,这很有帮助。