如何使用API​​View中的表单在Django中发送发布请求

时间:2019-07-07 03:45:16

标签: django django-rest-framework django-forms django-templates django-views

我正在使用基于类的视图制作OTP应用。底部是用于生成OTP并将其发送到电话号码的类。 模板工作正常,当我按html表单中的“提交”按钮时,它将发送发布请求,并返回响应: “未在要求后提供电话号码” 因此模板和API都可以!但是html模板中的{{form}}不起作用,因此我无法将OTP发送到表单中提交的号码。

那我在做什么错呢? forms.py存在于我的项目中,具有1个字段

class ValidatePhoneSendOTP(APIView,TemplateView):
    template_name = 'accs/reg.html'
    def post(self, request, *args, **kwargs):
        form = PhoneRegForm(request.POST)
        phone_number = request.data.get('phone')
        if phone_number:
            phone =  str(phone_number)
            user = User.objects.filter(phone_number__iexact = phone)
            if user.exists():
                return Response({
                    'status': False,
                    'detail': 'user exists'
                })

.
.
.
.
.
.
.
.

        else:
            return Response({
                'status' : False,
                'detail' : 'phone number is not given in post req'


            })

我试图在APIView,TemplateView之后的类中传递FormView,但是我无法使它正常工作。

0 个答案:

没有答案