Reputation: 1300
I know this question is too primitive but I'm totally new in web application development and I still haven't found an answer for it. When you want to receives some data from the user like the number of products the user wants to buy in a template like this:
form action="/pay/" method="POST">
{% csrf_token %}
<label for="pid">Book ID</label>
<input type="text" name="pid" value={{pid}} />
<br/>
<label for="sid">Seller ID</label>
<input type="text" name="sid" value={{sid}} />
<br/>
<input type="hidden" name="success_url" value="http://localhost:8000/payment/success" />
<input type="hidden" name="cancel_url" value="http://localhost:8000/payment/cancel" />
<input type="hidden" name="error_url" value="http://localhost:8000/payment/error" />
<p>Checksum test: {{checksum}}</p>
<input type="text" name="checksum" value={{checksum}}/>
</br>
<label for="id_amount">Please enter the number of products you would like to buy </label>
<input type="text" id="id_amount" name="amount" value=""/>
<input type="submit" value="Accept payment" />
</form>
how do you read that input in the view? For example, how can I print that input?
My view is like this:
def get_payment_detail(request, pid, sid):
checksum = Payment().calc_checksum()
return render_to_response('payment/payment.html', RequestContext(request, {'pid':Payment.pid,
'sid':Payment.sid,
'amount':Payment.amount,
'checksum': checksum
}))
Upvotes: 3
Views: 6482
Reputation: 459
You can access the form data off of request.POST. For example:
request.POST['pid']
Upvotes: 3