直接上代码吧
views视图写法:
def test(request):
if 'a' not in request.POST:
return render_to_response('test.html')
c=request.POST['a']
return HttpResponse("OK %s" %c)
模板写法:
<form action=" " method="post">
<select name="a" >
<option value="一上方">a</option>
<option value="二五道">b</option>
<option value="三天按">c</option>
<option value="四撒大">d</option>
<option value="五中的">e</option>
<option value="六稳定">f</option>
</select>
<input type="submit" value="测试"/>
</form>
##############################################
打印post请求,利于测试提交的变量
def test(request):
values = request.META.items()
values.sort()
html = []
for k, v in values:
html.append('<tr><td>%s</td><td>%s</td></tr>' % (k, v))
return HttpResponse('<table>%s</table>' % '\n'.join(html))