Python 如何使用Django/Twilio回复短信
我设置了一个页面“example.com/firstsms”,通过Twilio发送短信息,并重定向到主页。如果我用手机回复信息,我想回复确认信息。到目前为止,一切都没有发生 在url.py中,我有:Python 如何使用Django/Twilio回复短信,python,django,twilio,Python,Django,Twilio,我设置了一个页面“example.com/firstsms”,通过Twilio发送短信息,并重定向到主页。如果我用手机回复信息,我想回复确认信息。到目前为止,一切都没有发生 在url.py中,我有: (r'^hellomonkey/$', 'crusher.views.HelloMonkey'), 在views.py中,我尝试调整他们的: 绞尽脑汁!谢谢您正在返回一个HttpResponseRedirect,因此它将尝试重定向到某个页面,当然它不起作用。您应该改用HttpResponse: f
(r'^hellomonkey/$', 'crusher.views.HelloMonkey'),
在views.py中,我尝试调整他们的:
绞尽脑汁!谢谢您正在返回一个
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))
您正在返回一个
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))
Twilio的Devangelist在这里,我一直在维护Django Twilio库,有一个更简单的解决方案,可以用Twilio响应短信和语音 首先 然后在您的视图中,您可以使用
twilio\u视图
装饰器,如下所示:
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将为您处理正确的HTTPResponse内容,并确保请求来自真正的twilio.com来源。twilio的Devangelist在这里,我一直在维护Django twilio库,并且有一个更简单的解决方案,可以使用twilio响应短信和语音 首先 然后在您的视图中,您可以使用
twilio\u视图
装饰器,如下所示:
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将为您处理正确的HTTPResponse内容,并确保请求来自真正的twilio.com来源。谢谢!我已经尝试创建有条件的回答,并开始了另一个问题谢谢!我试图创建有条件的回答,并开始了另一个问题