Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.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
Django 显示选项的描述性状态_Django - Fatal编程技术网

Django 显示选项的描述性状态

Django 显示选项的描述性状态,django,Django,我在modles.py中定义了一个article_表模型数据,特别是为状态设置了选项属性 class Article(models.Model): STATUS = ( (0, 'normal'), (-1, 'deleted'), ) block = models.ForeignKey(Block, on_delete=models.CASCADE) title = models.CharField(max_length=100

我在modles.py中定义了一个article_表模型数据,特别是为
状态设置了
选项
属性

class Article(models.Model):
    STATUS = (
        (0,  'normal'),
        (-1, 'deleted'),
    )
    block = models.ForeignKey(Block, on_delete=models.CASCADE)
    title = models.CharField(max_length=100)
    author = models.CharField(max_length=100)
    content = models.CharField(max_length=1000) # set the widget
    status = models.IntegerField(choices=STATUS)
    date_created = models.DateTimeField(default=datetime.now)
    date_updated = models.DateTimeField(auto_now=True)


    def __str__(self):
        return self.title
当我检查响应的html时,它显示数据库中
0
的状态,而不是其描述“正常”

状态未按我的预期显示
normal

article\u list.html的模板

<table class="table table-bordered">
    <tr>
        <th>Status</th>
        <th>Title</th>
        <th>Author</th>
        <th>Latest Updated</th>
    </tr>
    {% for article in articles %}
    <tr>
        <td>{{ article.status }}</td>
        <td>{{ article.title }}</td>
        <td>{{ article.author }}</td>
        <td>{{ article.date_updated }}</td>
    </tr>
    {% endfor %}
</table>

地位
标题
作者
最新更新
{文章%中的文章为%s}
{{article.status}
{{article.title}}
{{article.author}}
{{article.date_updated}
{%endfor%}
如何解决这样的问题?

如果使用,则可以在模板中使用,如下所示:

{{ article.get_status_display }}
此处的文档: