表中的Django选择选项不起作用

时间:2019-03-14 07:54:23

标签: python django select option

我想在Django表中使用选择选项,但这不起作用。

screenshot

myview.py

def Data_Handling(request) :
    if request.method == 'POST' :
        form = getValue(request.POST)
    else :
        form = getValue()

global excel_data_name

agrs = {"excel_data_name" : excel_data_name, "form" : form }

return render(request, 'ex01/data_handling.html', agrs )

myforms.py

class getValue(forms.Form) :
value = forms.ChoiceField(widget=forms.Select(choices=("A", "B", "C")))

myhtml

<td>
<form method = "post" action = "">
    {% csrf_token %}
    {{ form.as_p }}
</form></td>

然后,如何在每一行中获取选定的值?

1 个答案:

答案 0 :(得分:0)

尝试一下

class getValue(forms.Form) :
     value = forms.ChoiceField(choices=(('A', 'A'), 
                                   ('B', 'B'), 
                                   ('C', 'C')))