如何显示一个模板上的pdf文件从上传仅从管理员

2024-09-30 14:24:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用django管理员在我的网站上提供PDF文档。我完全迷路了这就是我的模特儿

class Examination(models.Model):
    examination_name = models.CharField(max_length=50)

    class Meta:
        verbose_name='examination'
        verbose_name_plural='examinations' 

    def __unicode__(self):
        return self.examination_name


# Create your models here.
class Year(models.Model):
    examinations = models.ForeignKey('Examination')
    examination_year = models.CharField(max_length=4)

    class Meta:
        verbose_name='year'
        verbose_name_plural='years'

    def __unicode__(self):
        return self.examination_year


class PastQuestion(models.Model):
    years = models.ForeignKey(Year)
    file = models.FileField(upload_to='uploads/', max_length=100,)
    posted_by = models.CharField(max_length=50)


    def __unicode__(self):
        return self.years

当我试图从我的管理界面打开PastQuestion时,会出现这个错误。 在/admin/PastQuestion/PastQuestion/

强制到Unicode:需要字符串或缓冲区,Year发现如何正确地执行此操作

这是我点击PastQuestion时得到的错误

在/admin/PastQuestion/PastQuestion/

强制为Unicode:需要字符串或缓冲区,找到年份

请求方法:GET 请求URL:http://127.0.0.1:8000/admin/PastQuestion/pastquestion/ Django版本:1.10 异常类型:TypeError 异常值:

强制为Unicode:需要字符串或缓冲区,找到年份

异常位置:/home/tomms/Desktop/project/local/lib/python2.7/site-packages/django/utils/编码.py有效文本,第78行 Python可执行文件:/home/tomms/Desktop/project/bin/Python Python版本:2.7.9 Python路径:

['/home/tomms/Desktop/project/source', '/home/tomms/Desktop/project/lib/python2.7', '/home/tomms/Desktop/project/lib/python2.7/plat-x86_64-linux-gnu', '/home/tomms/Desktop/project/lib/python2.7/lib tk', '/home/tomms/Desktop/project/lib/python2.7/lib old', '/home/tomms/Desktop/project/lib/python2.7/lib dynload', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib tk', '/home/tomms/Desktop/project/local/lib/python2.7/site packages', '/home/tomms/Desktop/project/lib/python2.7/site packages']

服务器时间:2017年8月23日星期三01:54:37+0000 模板呈现时出错

在template/home/tomms/Desktop/project/local/lib/python2.7/site-packages/django/contrib/admin/templates/admin/change中_列表.html,第82行出错


Tags: nameselfprojecthomeverboseadminmodelslib