使用Django / Twilio进行条件短信响应

时间:2013-08-01 06:31:59

标签: python django twilio

我正在尝试根据不同的参数(来电显示,文本正文)调整短信响应,错误是“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

1 个答案:

答案 0 :(得分:2)

实际上在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 ....

希望它有所帮助!