如何在表单字段中获取值

时间:2013-09-11 07:21:46

标签: django django-templates

我有一个模板。这是我的模板

<form id="cal" method="get">
    <span>Number1</span>
    <input type="text" id="number1" name="number1"><br/>
    <span>Number2</span>
    <input type="text" id="number2" name="number2"><br/>
    <input tye"text" id="result">
    <input type="submit" value="calculated">
</form>

如何获取值number1和number2,并计算number1和number2

1 个答案:

答案 0 :(得分:0)

在您看来:

def my_view(request):
    number1 = request.POST.get('number1', None)

https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.POST