【问题标题】:Django select option in table not working表中的 Django 选择选项不起作用
【发布时间】:2019-03-14 07:54:23
【问题描述】:

我想在 Django 的表格中使用 select 选项,但它不起作用。

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")))

我的html

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

而且,我怎样才能在每一行中获得一个选定的值?

【问题讨论】:

  • 您好,欢迎来到 SO。您能否更清楚地了解您正在使用的数据源。目前还不清楚你到底想做什么。
  • 缩进在 Python 中很重要。请修正您的缩进,使其有意义。
  • 除非必要,否则不要使用global!并且类名的第一个字符大写。见:python.org/dev/peps/pep-0008

标签: python django select option


【解决方案1】:

试试这个

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

【讨论】:

  • 如果可行,则将我的答案标记为正确并投票
  • 你知道我怎样才能得到一个选定的值吗???如果我选择了“A”,我想保存“A”。
  • initial='A' 在 ChoiceField 内
猜你喜欢
  • 2020-04-27
  • 2020-05-01
  • 2018-10-02
  • 2013-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多