如何使用Django / Twilio响应短信(How to respond to text message with Django/Twilio)
我设置了一个页面“example.com/firstsms”,通过Twilio发送短信并重定向到主页。 如果我然后使用手机回复我要回复的确认消息。 截至目前,没有任何事情发生。
在urls.py我有:
(r'^hellomonkey/$', 'crusher.views.HelloMonkey'),在views.py中,我尝试调整他们的Flask示例 :
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")绞尽脑汁! 谢谢
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
最满意答案
您正在返回一个HttpResponseRedirect因此它会尝试重定向到某个页面,当然它不起作用。 您应该使用HttpResponse :
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))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))更多推荐
发布评论