2

我正在尝试根据不同的参数(呼叫者 ID、文本正文)调整 SMS 响应,错误是“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"]

谢谢编辑:忘记链接

4

1 回答 1

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 ....

希望能帮助到你!

于 2013-08-01T07:08:03.970 回答