我尝试根据不同的参数(来电显示、文本正文)调整短信响应,错误是“HTTP 检索失败” 我尝试过针对不同的调用者使用 Flask 教程:
def hello_monkey():
"""Respond and greet the caller by name."""
from_number = request.values.get('From', None)
if from_number in callers:
message = callers[from_number] + ", thanks for the message!"
else:
message = "Monkey, thanks for the message!"
但我意识到 Django 可能有所不同,所以我尝试了这些和其他几个:
def hello_monkey(request, From)
#with
from = From
def hello_monkey(request):
#with
number = request.POST["Body"]
谢谢 编辑:忘记了link
最佳答案
实际上在 Django 中它会非常相似,你应该阅读更多关于 request 的内容。 。由于您不知道请求是 POST 还是 GET,因此可以使用 HttpRequest.REQUEST
:
callers = {
"+14158675309": "Curious George",
"+14158675310": "Boots",
"+14158675311": "Virgil",
}
def hello_monkey(request):
"""Respond and greet the caller by name."""
from_number = request.REQUEST.get('From', None)
if from_number in callers:
message = callers[from_number] + ", thanks for the message!"
else:
message = "Monkey, thanks for the message!"
# .... your code ....
希望对你有帮助!
关于python - 使用 Django/Twilio 进行条件短信响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17986721/