1

I set up a page "example.com/firstsms" to send a SMS through Twilio and redirect to the homepage. If I then use the phone to respond to the message I want to reply with a confirmation. As of now, nothing happens.

In urls.py I have:

(r'^hellomonkey/$', 'crusher.views.HelloMonkey'),

In views.py I tried to adapt their Flask example:

def HelloMonkey(request):
    """Respond to incoming calls with a simple text message."""

    resp = twilio.twiml.Response()
    resp.sms("Hello, Mobile Monkey") 
    return HttpResponseRedirect(str(resp), content_type="text/plain")

Racking my brain! Thanks

4

2 回答 2

3

You are returning a HttpResponseRedirect so it would try to redirect to some page and of course it doesn't work. You should use HttpResponse instead:

from django.http import HttpResponse

def HelloMonkey(request):
    """Respond to incoming calls with a simple text message."""

    resp = twilio.twiml.Response()
    resp.sms("Hello, Mobile Monkey") 
    return HttpResponse(str(resp))
于 2013-07-31T22:35:53.320 回答
1

Devangelist from Twilio here, I've been maintaining the Django-twilio library and there is a much easier solution to responding to SMS and Voice with Twilio.

First, pip install django-twilio and get it set up using the instructions here.

Then in your view you can use the twilio_view decorator like so:

from django_twilio.decorators import twilio_view
from twilio.twiml import Response    

@twilio_view
def my_view(request):
    r = Response()
    r.message('Hello, world!')
    return r

Django-twilio will handle the correct HTTPResponse stuff for you, as well as ensure the request is coming from a genuine twilio.com source.

于 2014-10-19T18:06:10.307 回答