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!

分享到:
评论