一视图两页DJANGO注册并验证

时间:2018-07-11 13:50:32

标签: django django-forms django-templates django-views django-socialauth

谁能建议一种使我的代码正常工作的最佳方法
我创建了一个注册视图,逻辑看起来像这样

def signup(request):
    if request.method == 'POST':
        form = UserRegistrationForm(request.POST)
        verify=VerificationForm(request.POST)
        print(verify)
        if form.is_valid():
            userObj = form.cleaned_data
            username = userObj['username']
            email =  userObj['email']
            password =  userObj['password']

这是signup.html

{% extends 'question/index.html '%}

{% block body_block %}
<div class="conrainer">


  <form method="POST">
      {% csrf_token %} {{ form.as_p }}
      <button type="submit">Submit</button>
  </form>
  <a href="{% url 'social:begin' 'facebook'%}">facebook auth</a>

</div>
{% endblock %} 

我想当用户单击“提交”时,必须将他重定向到另一个页面,例如verfication.html,在该页面中,用户必须提交六位数字的代码,而当他单击“提交”时,应该执行用户创建逻辑

    if not (User.objects.filter(username=username).exists() or User.objects.filter(email=email).exists()):
        User.objects.create_user(username, email, password)
        user = authenticate(username = username, password = password)
        login(request, user)
        return HttpResponseRedirect('/')
    else:
        raise forms.ValidationError('Looks like a username with that email or password already exists')
else:
    raise forms.ValidationError('Looks like form is invalid')


else:
    form = UserRegistrationForm()

return render(request, 'question/signup.html', context= {'form' : form })

有人能建议我实现这一目标的最佳方法吗?
任何帮助都表示赞赏
预先感谢

0 个答案:

没有答案