Twilio与Django用于OTP

时间:2019-03-12 14:40:41

标签: python django twilio twilio-api

我正在尝试验证电话号码,并在django中向其发送otp,但是出现此错误400客户端错误:URL:https://api.twilio.com/2010-04-01/Accounts/ACb72b622666f57139034b55062d3bbe9c/Messages.json的请求不正确。

来自twilio的消息是:

{"first_page_uri": "/2010-04-01/Accounts/ACb72b622666f57139034b55062d3bbe9c/Messages.json?PageSize=50&Page=0", "end": 0, "previous_page_uri": null, "messages": [], "uri": "/2010-04-01/Accounts/ACb72b622666f57139034b55062d3bbe9c/Messages.json?PageSize=50&Page=0", "page_size": 50, "start": 0, "next_page_uri": null, "page": 0}

这是我在view.py中的注册功能

def otp_register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = form.save()
            phone_number = form.cleaned_data.get('phone_number')
            if user.id:
                user.twiliosmsdevice_set.create(name='SMS', number=phone_number)
                device = user.twiliosmsdevice_set.get()
                device.generate_challenge()
            return HttpResponseRedirect('/Nittanfund/verify')
    else:
        form = RegistrationForm()
    context = {}
    context.update(request)
    context['form'] = form
    return render(request, 'signup.html', context)

0 个答案:

没有答案