老师您好,本章有如下几个问题想要请教下
if login_form.is_valid():
mobile = login_form.cleaned_data['mobile']
# 验证用户是否存在
exist_user = UserProfile.objects.filter(mobile=mobile)
if exist_user:
user = exist_user[0]
else:
# 如果用户不存在,注册新建
user = UserProfile(mobile=mobile)
password = generate_code(1, 6)
user.set_password(password)
username = generate_code(2,4)
user.username = username
user.mobile = mobile
user.save()
login(request, user)
return redirect(reverse('index'))
# form表单
class DynamicLoginForm(forms.Form):
mobile = forms.CharField(required=True, max_length=11, min_length=11)
captcha = CaptchaField()
class DynamicLoginPostForm(forms.Form):
mobile = forms.CharField(required=True, max_length=11, min_length=11)
code = forms.CharField(required=True,min_length=4, max_length=4)
# view视图
class SendSmsView(View):
def post(self, request):
send_form = DynamicLoginForm(request.POST)
'''
class DynamicLoginView(View):
def post(self, request):
login_form = DynamicLoginPostForm(request.POST) #
dynamic_form = DynamicLoginForm(request.POST)
'''
# 前端login.html
<div class="form-group marb20 blur" id="jsRefreshCode">
{{ login_form.captcha }}
{{ dynamic_form.captcha }}
</div>