python - 如何用Django/Twilio回复短信

标签 python django twilio

我设置了一个页面“example.com/firstsms”以通过 Twilio 发送短信并重定向到主页。如果我然后使用电话回复消息,我想回复确认。截至目前,没有任何反应。

在 urls.py 中我有:

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

在 views.py 中我试图调整他们的 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")

绞尽脑汁!谢谢

最佳答案

你正在返回一个 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))

关于python - 如何用Django/Twilio回复短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17982019/

相关文章:

python - 从 pytorch 的 torchtext 库中保存词汇对象

python - 如何解决错误 "object_permission() takes 3 positional arguments but 4 were given"?

java - 如何使用 Java 中的 Twilio API 和 Rest API 将文本转换为语音

python - HTTP 检索错误 Twilio

python - 如何检查Python中的函数装饰器

python - 求和一列值,包括 Python 中的字母

python - 如何使 Socket.IO 客户端连接到 Python3 Websocket 服务器

python - 即使使用 DJANGO 模型表单提交后,图片也不会在数据库中更新

python - 使用 Rest-Framework-Jwt 创建 token

php - 如何解决 ubuntu 中的 SSL 证书错误