简体   繁体   中英

Sending email after POST request with Django and Tastypie

I am using Tastypie to create an API for a Django project. What I'd like to do is to send an email after a POST request to a vouchers resource (creating a new voucher). Does anybody know what's the best solution to this problem?

I am not sure how can I intercept the request and process it. A solution that comes to mind is to override the model's constructor and send the email when the instance is created! I don't know whether this is a good idea or not.

The answer to this question seems a possible solution: Adding to the "constructor" of a django model

Use post_save in Django Signals. https://docs.djangoproject.com/en/dev/topics/signals/

You can check the created parameter to know if you need to send an email.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM