Python 如何将OTP发送到Django的电话号码?

Python 如何将OTP发送到Django的电话号码?,python,django,twilio,one-time-password,Python,Django,Twilio,One Time Password,我需要在提交表格时验证电话号码(无需登录和注册)。我正在使用Twilio服务。请告诉我怎么做。我需要发送OTP的用户填写表格中的数字,然后验证,然后提交表格。提前谢谢 我的型号: class Booking(models.Model): date = models.CharField(max_length=200,blank=True, db_index=True, null=True ) time

我需要在提交表格时验证电话号码(无需登录和注册)。我正在使用Twilio服务。请告诉我怎么做。我需要发送OTP的用户填写表格中的数字,然后验证,然后提交表格。提前谢谢

我的型号:

class Booking(models.Model):
            date                        = models.CharField(max_length=200,blank=True, db_index=True, null=True )
            time                        = models.CharField(max_length=200,blank=True, db_index=True, null=True )
            name                        = models.CharField(max_length=200,blank=True, db_index=True, null=True )
            email                       = models.CharField(max_length=200,blank=True, db_index=True, null=True )
            product                     = models.CharField(max_length=200,blank=True, db_index=True, null=True )
            phone                       = models.IntegerField(max_length=200,blank=True, db_index=True, null=True )
            address                     = models.TextField(max_length=200,blank=True, db_index=True, null=True ) 
    
    otp                     = models.CharField(max_length=6,blank=True, db_index=True, null=True )
我的观点

import os
from twilio.rest import Client
from django.shortcuts import render, get_object_or_404, redirect
from .models import Product,Technician,FAQ, Booking

def booking(request,slug=None,pk=None):
    products = get_object_or_404(Product,slug=slug)
    if request.method == 'POST':
        date = request.POST['date']
        time = request.POST['time']
        name = request.POST['name']
        email = request.POST['email']
        product = request.POST['product']
        phone = request.POST['phone']
        address = request.POST['address']
        otp = ran()
                
        data  = Booking(date=date, time=time, name=name, email=email, product=product, phone=phone, address=address,otp=otp)
        data.save()
        send_otp(phone,otp)
        request.session['phone'] = phone
        return redirect('otp')       

    else:
        return render(request, 'book.html', {'product' : products})


def send_otp(phone,otp):
    account_sid = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
    auth_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    client = Client(account_sid, auth_token)
    message = client.messages \
            .create(
                     body="Join Earth's mightiest heroes. Like Kevin Bacon.",
                     from_='+xxxxxxxxx',
                     to=phone
                 )
    return message


def otp(request):
    phone = request.session['phone']
    return render(request, 'otp.html',{'phone':phone})