Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 这是什么数据?_Python_Django_Pdf_Types_Binary - Fatal编程技术网

Python 这是什么数据?

Python 这是什么数据?,python,django,pdf,types,binary,Python,Django,Pdf,Types,Binary,我正在使用Django,我正在获取一个存储在中的pdf文件,并尝试将其作为数据类型发送到响应中(最好是,我希望根据客户机的请求以尽可能多的数据类型发送) 使用python库执行GET请求时,我得到以下数据: '...0000000123 65535 f\r\n0000000124 65535 f\r\n0000000125 65535 f\r\n0000000126 65535 f\r\n0000000127 65535 f\r\n0000000128 65535 f\r\n000000012

我正在使用Django,我正在获取一个存储在中的pdf文件,并尝试将其作为数据类型发送到响应中(最好是,我希望根据客户机的请求以尽可能多的数据类型发送)

使用python库执行GET请求时,我得到以下数据:

'...0000000123 65535 f\r\n0000000124 65535 f\r\n0000000125 65535 f\r\n0000000126 65535 f\r\n0000000127 
65535 f\r\n0000000128 65535 f\r\n0000000129 65535 f\r\n0000000130 65535 f\r\n0000000131 65535 
f\r\n0000000132 65535 f\r\n0000000133 65535 f\r\n0000000134 65535 f\r\n0000000135 65535 
f\r\n0000000136 65535 f\r\n0000000137 65535 f\r\n0000000138 65535 f\r\n0000000139 65535 
f\r\n0000000140 65535 f\r\n0000000141 65535 f\r\n0000000142 65535 f\r\n0000000143 65535 
f\r\n0000000144 65535 f\r\n0000000145 65535 f\r\n0000000146 65535 f\r\n0000000147 65535 
f\r\n0000000148 65535 f\r\n0000000149 65535 f\r\n0000000000 65535 f\r\n0000032441 00000 
n\r\n0000032871 00000 n\r\n0000235049 00000 n\r\n0000235493 00000 n\r\n0000236007 00000 
n\r\n0000236479 00000 n\r\n0000432257 00000 n\r\n0000432285 00000 n\r\n0000432726 00000 
n\r\n0000647350 00000 n\r\n0000647920 00000 n\r\n0000648462 00000 n\r\n0000648763 00000 
n\r\n0000661917 00000 n\r\n0000661961 00000 n\r\n0000662439 00000 n\r\n0000778958 00000 
n\r\n0000778986 00000 n\r\n0000798973 00000 n\r\ntrailer\r\n<</Size 169/Root 1 0 R/Info 36 0 
R/ID[<B3EBF57233FC8C4C9A30C5ED4E046BAA><B3EBF57233FC8C4C9A30C5ED4E046BAA>] 
>>\r\nstartxref\r\n799587\r\n%%EOF\r\nxref\r\n0 0\r\ntrailer\r\n<</Size 169/Root 1 0 R/Info 36 0 
R/ID[<B3EBF57233FC8C4C9A30C5ED4E046BAA><B3EBF57233FC8C4C9A30C5ED4E046BAA>] /Prev 799587/XRefStm 
798973>>\r\nstartxref\r\n803127\r\n%%EOF\r\n--ff856adc8f49533d56f779b14dcf63e8--\r\n'
“…0000000 123 65535 f\r\n0000000124 65535 f\r\n0000000125 65535 f\r\n0000000126 65535 f\r\n0000000127
65535 f\r\n0000000128 65535 f\r\n0000000129 65535 f\r\n0000000130 65535 f\r\n0000000131 65535
f\r\n0000000132 65535 f\r\n0000000133 65535 f\r\n0000000134 65535 f\r\n0000000135 65535
f\r\n0000000136 65535 f\r\n0000000137 65535 f\r\n0000000138 65535 f\r\n0000000139 65535
f\r\n0000000140 65535 f\r\n0000000141 65535 f\r\n0000000142 65535 f\r\n0000000143 65535
f\r\n00000001465535 f\r\n0000000145 65535 f\r\n0000000146 65535 f\r\n0000000147 65535
f\r\n0000000148 65535 f\r\n0000000149 65535 f\r\n0000000000 65535 f\r\n0000032441 00000
n\r\n0000032871 00000 n\r\n0000235049 00000 n\r\n0000235493 00000 n\r\n0000236007 00000
n\r\n0000236479 00000 n\r\n0000432257 00000 n\r\n0000432285 00000 n\r\n0000432726 00000
n\r\n0000647350 00000 n\r\n00006479200000 n\r\n0000648462 00000 n\r\n0000648763 00000
n\r\n0000661917 00000 n\r\n00006611961 00000 n\r\n0000662439 00000 n\r\n0000778958 00000
n\r\n0000778986 00000n\r\n0000798973 00000n\r\n轨道器\r\n\r\nstartxref\r\n799587\r\n%%EOF\r\nxref\r\n0\r\ntrailer\n\r\nstartxref\r\n803127\r\n%%EOF\r\n--FF856ADC8F49533D56F7799B14DC63E8--\r\n

这是什么数据类型?

在我的一个项目中,我为课堂成绩创建了一个文件服务函数:

因此,为文件服务的代码部分是:

 with open(file_path, 'rb') as fh:
     response = HttpResponse(fh.read(), content_type="application/default")
     response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path)
     return response
您需要做的是将PDFfilepath放在变量'file_path'中,它将工作(我想)

 with open(file_path, 'rb') as fh:
     response = HttpResponse(fh.read(), content_type="application/default")
     response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path)
     return response