躺在沙滩上的小猪

快乐的每一天

Can't get params from HttpRequest.POST

I create a template following django's document:

<h1>{{poll.question}}</h1>
{%if error_message%}
<p><strong>{{error_message}}</strong></p>{%endif%}

<form action="/polls/{{poll.id}}/vote" method="post">
    {%for choice in poll.get_choice_list%}
        
<input type="radio" name="choice" id="choice{{forloop.counter}}" value="{{choice.id}}"/>
        
<label for="choice{{forloop.counter}}">{{choice.choice}}</label><br/>
    {%endfor%}
    
<input type="submit" value="Vote">
</form>

And try to get params from post in python:

def vote(request, poll_id):
    p 
= get_object_or_404(polls, pk=poll_id)
    
print request.GET
    
print request.POST    
    
return HttpResponseRedirect('/polls/%s/results/' % p.id)

But the result was null:(

{}
{}

While I change the method to get

<form action="/polls/{{poll.id}}/vote" method="get">

I can get the params's value.
{'choice': ['1']}
{}

I don't know why,I wanna help!

posted on 2005-12-29 12:47 martin xus 阅读(283) 评论(1)  编辑  收藏 所属分类: python