Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.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
Python 如何获取小部件select的值?_Python_Django - Fatal编程技术网

Python 如何获取小部件select的值?

Python 如何获取小部件select的值?,python,django,Python,Django,请帮助选择小部件的选定值 model.py: class UserProfile(User): CHOICES_teacher = ( ('0', 'qwe', ), ('1', 'asd',), ('2', 'zxc', ), ) teacher = models.CharField( 'teacher', max_length=30, ch

请帮助选择小部件的选定值

model.py:

class UserProfile(User):        
    CHOICES_teacher = (
        ('0', 'qwe', ),
        ('1', 'asd',),
        ('2', 'zxc', ),
    )       

    teacher = models.CharField(
        'teacher',
        max_length=30, 
        choices=CHOICES_teacher,        
        blank=True,
        null=True,
    )
forms.py:

class DrumDataForm(forms.ModelForm):            
    class Meta:
        model = UserProfile
        fields = (
            'teacher', 
        )
template.html:

{% if entries_user_profile.teacher %}
    <div class="teacher">{{ entries_user_profile.teacher }}</div>
{% endif %} 
{%if条目\用户\配置文件.teacher%}
{{entries\u user\u profile.teacher}}
{%endif%}
问题是屏幕显示0、1或2。但我需要在屏幕qwe或asd或zxc上从以下位置查看它们:

{{ entries_user_profile.get_teacher_display }}
对于已设置的每个字段,对象将有一个get\u FOO\u display()方法,其中FOO是字段的名称。此方法返回字段的“人类可读”值

因此,在您的示例中,您可以使用以下方法访问字段的“人类可读”值:


{{entries\u user\u profile.get\u teacher\u display}

使用{{{entries\u user\u profile.teacher.1}