Django 檔案說可以使用,.label但在模板中不起作用。
class Model(models.Model):
class ModelChoices(models.TextChoices):
ENUM = 'VALUE', 'Label'
model_choice = models.CharField(choices=ModelChoices.choices)
在模板object.model_choice中顯示值 ( 'VALUE')。
object.model_choice.label什么都不顯示。
如何'Label'在模板中獲取標簽()?感謝您的時間和幫助,不勝感激。
uj5u.com熱心網友回復:
你會用get_{field_name}_display
Python
modelObj.get_model_choice_display()
模板
{{modelObj.get_model_choice_display}}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/508734.html
標籤:django
上一篇:創建模型后的DjangoModuleNotFoundError
下一篇:所有頁面的Django重定向
