我是Django的新手。我在模板文件中有一个HTML表单,并且只想将两个整数传递给视图函数。我阅读了表单和Widgets文档,但它太复杂了,我无法得到它。我坚信你们都有更好的主意。是否可以使用CGI?
HTML模板:
<form action = "http://127.0.0.1:8080/view/" method = "get" target="_blank">
<input type = "number" name = "Emp_ID">
<input type="number" name="Year" min="2013" max="2020" value = "2013">
<input type="submit" value="Run">
</form>
views.py:
from django.http import HttpResponse
def run_html(request):
return HttpResponse('i want to use Emp_ID & Year value here')
答案 0 :(得分:0)
您可以从request.GET
词典中获取值:
emp_id = request.GET['Emp_ID']
year = request.GET['Year']