如何在django应用程序中搜索和显示pdf文件?

我有一个Profile模型,可以为django的User模型添加更多字段,其中一个字段是pdf文件。我需要创建一个视图以搜索pdf并显示在浏览器中。这是我的代码:

def resume_view(request):
    url_resume = request.user.profile.resume.url
    cd = os.getcwd() + '{}'
    dir_resume = cd.format(url_resume)
    with open(dir_resume,'r') as pdf:
        response = HttpResponse(pdf.read(),mimetype='application/pdf')
        response['Content-Disposition'] = 'inline;filename=some_file.pdf'
        return response

问题是当我调用视图时出现此错误:

'charmap' codec can't decode byte 0x81 in position 506: character maps to <undefined>

我不知道这是否重要,但这是模型简介:

class Profile(models.Model):

    user = models.OneToOneField(User,on_delete=models.CASCADE)
    resume = models.FileField(upload_to=user_resume_path,null=False)

如何解决?

shaliang8 回答:如何在django应用程序中搜索和显示pdf文件?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3162743.html

大家都在问