def register(request): if request.method == "POST": uf = UserForm(request.POST) if uf.is_valid(): #获取表单信息 username = uf.cleaned_data['username'] password = uf.cleaned_data['password'] email = uf.cleaned_data['email'] #将表单写入数据库 user = User() user.username = username user.password = password user.email = email user.save() #返回注册成功页面 return render(request, 'success.html', {'username': username}) else: uf = UserForm() return render(request, 'register.html', {'uf': uf}) #return render(request, 'register.html')
def index(request): # photos = Photo.objects.all().order_by('position') files = Upload.objects.all().order_by('filename') # file_types = Upload.objects.all().order_by('file_type') # if request.method == 'GET': inputMail = request.GET.get('email', '') print(inputMail) ##验证邮箱的合法性 isMatch = bool( re.match( r"^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$", inputMail, re.VERBOSE)) #print(isMatch) if isMatch: ##邮箱去重 is_email_exist = User.objects.filter(email=inputMail).exists() if is_email_exist: # ret=0 # return HttpResponse(json.dumps({ # "ret": ret, # })) status = send_email(inputMail) if status: print("邮件发送成功") else: ##实例化用户表 user_profile = User() user_profile.email = inputMail user_profile.is_activate = False user_profile.save() ##发送邮件 #status = send_email(inputMail) #mess="订阅成功,我们将给你邮箱发送激活链接,注意查收" status = send_email(inputMail) if status: print("邮件发送成功") # else: # mess = "邮箱格式不正确" return render(request, 'index.html', locals())