如何获得单选按钮输入的值?

时间:2018-09-07 14:25:09

标签: python html django

如何获取输入值?我用HTML编写了代码,

<form action="{% url 'app:top' %}" method="POST">
              <input type="radio" name="no" value="1">
              <label>No</label>
              <input type="radio" name="yes" value="1">
              <label>Yes</label>
<input class="disabled" type="submit" value="POST">
</form>

views.py中;

def top(request):
    no = request.POST.get("no","0")
    yes = request.POST.get("yes","0")

    print(no)
    print(yes)

当我没有标签并放置发送按钮时,将打印0。放置是按钮是相同的。为什么会发生?为什么我不能打印出1?我该怎么办?

1 个答案:

答案 0 :(得分:0)

type Generic c = forall a. Data a => a -> c a

<form action="{% url 'app:top' %}" method="POST"> <input type="radio" name="answer" value="no"> <label>No</label> <input type="radio" name="answer" value="yes"> <label>Yes</label> <input type="submit" value="POST"> </form>

views.py