Python 如何在Django中读取pdf文件

Python 如何在Django中读取pdf文件,python,django,pdf,model,Python,Django,Pdf,Model,这是我的观点。。在空格打开后,我想读一个文件,但我不知道要写什么使它动态… def home(request): image_data = open('', 'rb').read() return HttpResponse(image_data, mimetype='application/pdf') 这是我的模型在此文件已上载。。其格式为pdf或.doc。。我想看上传的文件 from django.db import models class CV(models.Mode

这是我的观点。。在空格打开后,我想读一个文件,但我不知道要写什么使它动态…
def home(request):
    image_data = open('', 'rb').read()
    return HttpResponse(image_data, mimetype='application/pdf')
这是我的模型在此文件已上载。。其格式为pdf或.doc。。我想看上传的文件

from django.db import models


class CV(models.Model):
    file = models.FileField(upload_to='media')

试试这个

def home(request):
  file = request.FILES['yourHtmlFileFieldName']
  image_date = open(file,'rb').read()