views.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:marvin-django 作者: programa-stic 项目源码 文件源码
def src(request, app_id):
    myApp = get_object_or_404 (App, pk=app_id)
    mySources = myApp.sourcefile_set.all()
    temp = tempfile.TemporaryFile()
    arch = zipfile.ZipFile(temp, 'w')
    #old *working* code follows
    #myFileObj = io.BytesIO()
    #myZipFile = zipfile.ZipFile(myFileObj, 'w')
    for item in mySources:
        fname = item.file_name
        actualname = fname + '.java'
        src = (item.file_contents).encode('ascii','replace').replace("\\n", "\n")
        arch.writestr(actualname, src)
    arch.close()
    temp.seek(0)
    wrapper = FileWrapper(temp)
    response=HttpResponse(wrapper, content_type = "application/zip")
    response['Content-Disposition'] = 'attachment; filename="'+myApp.package_name+'.zip"'
    response ['Content-Length'] = temp.tell()
    return response
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号