Python 如何根据Django模板中的用户输入检查单选按钮?

Python 如何根据Django模板中的用户输入检查单选按钮?,python,django,Python,Django,如果两个输入字段的一个或两个值超过某个数字,我想检查一个特定的单选按钮。我目前正在使用Django表单呈现文本框和单选按钮: 像这样: 单选按钮: 'gap_result': HorizontalRadioSelect( choices=NG_gap, attrs={ 'default': 'OK', 'class': 'radio colorC', '

如果两个输入字段的一个或两个值超过某个数字,我想检查一个特定的单选按钮。我目前正在使用Django表单呈现文本框和单选按钮:

像这样:

单选按钮:

'gap_result': HorizontalRadioSelect(
            choices=NG_gap,
            attrs={
                'default': 'OK',
                'class': 'radio colorC',
                'style': ' margin-top: 15px; margin-left: 25px;',
                'name': 'radio_Gap',
                'id ': 'radio_Gap_Result',
            }),
        'gap_X': forms.TextInput(
            attrs={
                'class': 'form-control cent ',
                'placeholder': 'X',
                'type': 'text',
                'id': 'gap_X',
                # 'readonly': 'false',
            }),
        'gap_Y': forms.TextInput(
            attrs={
                'class': 'form-control cent ',
                'placeholder': 'Y',
                'type': 'text',
                'id': 'gap_Y',
            }),
两个文本框:

'gap_result': HorizontalRadioSelect(
            choices=NG_gap,
            attrs={
                'default': 'OK',
                'class': 'radio colorC',
                'style': ' margin-top: 15px; margin-left: 25px;',
                'name': 'radio_Gap',
                'id ': 'radio_Gap_Result',
            }),
        'gap_X': forms.TextInput(
            attrs={
                'class': 'form-control cent ',
                'placeholder': 'X',
                'type': 'text',
                'id': 'gap_X',
                # 'readonly': 'false',
            }),
        'gap_Y': forms.TextInput(
            attrs={
                'class': 'form-control cent ',
                'placeholder': 'Y',
                'type': 'text',
                'id': 'gap_Y',
            }),
如果两个值都不超过8,我需要将单选按钮更改为OK,如果超过8,则将单选按钮更改为NG

这是一个视觉表现:

以下是我在使用django表单的模板中的内容:

    <div class="row">
  <div class = "col-3">
    <div class="form-text">
      {{form.gap_X}}
    </div>
  </div>
  <div class = "col-3">
    <div class="form-text">
      {{form.gap_Y}}
    </div>
  </div>
    {{form.gap_result}}
</div>

{form.gap_X}
{form.gap_Y}
{{form.gap_result}
试试:


您需要使用每个单选按钮的ID进行更新

如果我在forms.py中声明了每个单选按钮的ID,您如何更新其ID?运行它并在浏览器中查看源代码。它将按ID列出它们。