Django页面没有加载异常' bytes'对象不是可调用的问题

时间:2017-08-16 12:44:37

标签: python django django-views

我正在Django中下载文件。我已将路径添加到urls.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))
    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

     

异常值:'字节'对象不可调用

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

删除此行:

render(request, 'personal/home.html')