Common use case:
User select item to add to cart
User makes p开发者_Go百科ayment via off site payment gateway such as paypal or worldpay
User gets redirect to payment page and makes payment
Payment portal sends a POST request to a callback URL
User gets redirected back to your page
On Step 4, typically the following things happen:
Error handling and anti fraud checking
Updating of order/cart models and additional logic
My question is pertaining to this step 4:
In apps like Django-Paypal, rather than do all the logic processing on the callback url view function, signals are used instead. Is there a good reason for this? Why not just do all the logic on the callback url view function?
The use of signals decouples django-paypal from your own apps. You can have all kinds of crazy custom stuff happening on payment success or failure in your projects and still use the default provided view.
The class based views in Django 1.3 do make it possible to extend views, and provide an alternative way to decoupling an apps view.
Other considerations you should have before putting logic in views is time; if logic could take a long time (like any I/O), ask yourself if they are crucial to the Response at hand and consider putting it in a task queue, so you can handle the Request quickly, without blocking.
精彩评论