zoukankan      html  css  js  c++  java
  • 返回pdf文档

    code

    #coding=utf-8
    from django.shortcuts import render
    from django.http import HttpResponse
    from django.core.paginator import Paginator,EmptyPage,PageNotAnInteger
    from django.utils import timezone
    from django.shortcuts import render,redirect
    from django.http import HttpResponse,HttpResponseRedirect,JsonResponse
    from django.shortcuts import render_to_response
    from booklist.models import bookinfoA as A
    from booklist.models import bookinfoB as B
    from booklist.models import bookinfoC as C
    import os,sys
    sys.path.append("/".join(os.path.dirname(os.path.abspath(__file__)).split("/")[:-1])+"/lib")
    from encrype import encry
    from django.http import StreamingHttpResponse
    from django.utils.encoding import escape_uri_path
    
    
    
    
    def file_iterator(file_name, chunk_size=512):
            with open(file_name,'rb') as f:
                while True:
                    c = f.read(chunk_size)
                    if c:
                        yield c
                    else:
                        break
    
    
    def extractfile(request,book_type,book_dir,book_id,book_name,book_format):
        enc=encry()
        book_id=int(enc.getdecrype(book_id))
        book_type=chr(enc.getdecrype(book_type))
    
    
        #book_dir=enc.decrypt_data(book_dir).decode()
        #print(book_id)
        #print(book_type)
        #print(book_dir)
        #print(timezone.now().strftime('%Y%m%d'))
    
    
        filepath="/".join(os.path.dirname(os.path.abspath(__file__)).split("/")[:-1])+"/files/"
    
    
        file_dir="/".join(list(book_dir.split('#')[0]))
    
    
        file=book_name+"."+book_format
        the_file_name = filepath+file_dir+"/"+file
    
    
        response = StreamingHttpResponse(file_iterator(the_file_name))
        response['Content-Type'] = 'application/octet-stream'
        response['Content-Disposition'] = 'attachment;filename="{0}"'.format(escape_uri_path(file))
        return response

  • 相关阅读:
    CString常用方法简介
    @PostConstruct与@PreDestroy
    Servlet知识
    Extjs ——radiogroup子元素宽度调整
    JS的Document属性和方法
    sql server
    C#中的结构,练习
    datagridview实现复制粘贴
    VS.NET2010水晶报表安装部署[VS2010]
    C#中基础知识积累
  • 原文地址:https://www.cnblogs.com/sea-stream/p/14182274.html
Copyright © 2011-2022 走看看