我正在使用Django,我得到了一个存储在BinaryField中的pdf文件,并试图将其作为数据类型在响应中发送(最好是,我希望根据客户端的请求,尽可能多地发送数据类型(。
class CVPdf(generics.UpdateAPIView):
permission_classes = [IsAuthenticated]
parser_classes = [FileUploadParser]
def get(self, *args):
"""
* ``:param request:`` GET request sent with ``Authorization: Bearer token_id``.
* ``:return:`` Authenticated Seeker CV file
"""
pdf_file= CV.objects.get(id=1).pdf_file
return HttpResponse(pdf_file)
使用python请求库执行GET请求时,我得到了以下数据:
'...0000000123 65535 frn0000000124 65535 frn0000000125 65535 frn0000000126 65535 frn0000000127
65535 frn0000000128 65535 frn0000000129 65535 frn0000000130 65535 frn0000000131 65535
frn0000000132 65535 frn0000000133 65535 frn0000000134 65535 frn0000000135 65535
frn0000000136 65535 frn0000000137 65535 frn0000000138 65535 frn0000000139 65535
frn0000000140 65535 frn0000000141 65535 frn0000000142 65535 frn0000000143 65535
frn0000000144 65535 frn0000000145 65535 frn0000000146 65535 frn0000000147 65535
frn0000000148 65535 frn0000000149 65535 frn0000000000 65535 frn0000032441 00000
nrn0000032871 00000 nrn0000235049 00000 nrn0000235493 00000 nrn0000236007 00000
nrn0000236479 00000 nrn0000432257 00000 nrn0000432285 00000 nrn0000432726 00000
nrn0000647350 00000 nrn0000647920 00000 nrn0000648462 00000 nrn0000648763 00000
nrn0000661917 00000 nrn0000661961 00000 nrn0000662439 00000 nrn0000778958 00000
nrn0000778986 00000 nrn0000798973 00000 nrntrailerrn<</Size 169/Root 1 0 R/Info 36 0
R/ID[<B3EBF57233FC8C4C9A30C5ED4E046BAA><B3EBF57233FC8C4C9A30C5ED4E046BAA>]
>>rnstartxrefrn799587rn%%EOFrnxrefrn0 0rntrailerrn<</Size 169/Root 1 0 R/Info 36 0
R/ID[<B3EBF57233FC8C4C9A30C5ED4E046BAA><B3EBF57233FC8C4C9A30C5ED4E046BAA>] /Prev 799587/XRefStm
798973>>rnstartxrefrn803127rn%%EOFrn--ff856adc8f49533d56f779b14dcf63e8--rn'
这是什么数据类型?
在我的一个项目中,我为课堂分数制作了一个文件服务功能:
因此,为文件提供服务的代码部分是:
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"中,它会起作用(我想(