如何获取输入值?我用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?我该怎么办?
答案 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