如何使用Django / Twilio响应短信(How to respond to text message with Django/Twilio)

编程入门 行业动态 更新时间:2024-10-26 09:18:49
如何使用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))

更多推荐

本文发布于:2023-07-22 19:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222777.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   短信   Django   message   Twilio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!