def post(self, request, *args, **kwargs):
"""Post response."""
self.object = None
self.form = self.get_form(self.form_class)
# Here ou may consider creating a new instance of form_class(),
# so that the form will come clean.
text = self.form.save()
text.sender = 'you'
text.contact = Contact.objects.get(pk=int(self.kwargs.get('pk')))
account_sid = os.environ["ACCOUNT_SID"]
auth_token = os.environ["AUTH_TOKEN"]
twilio_number = os.environ["TWILIO_NUMBER"]
client = TwilioRestClient(account_sid, auth_token)
client.messages.create(
to=str(text.contact.number),
from_=twilio_number,
body=text.body
)
text.save()
return self.get(request, *args, **kwargs)
评论列表
文章目录