ARJhe / Django_tutorial-Blog

0 stars 0 forks source link

Register app form.is_valid() = False #4

Open ARJhe opened 4 years ago

ARJhe commented 4 years ago

After filled name,password and recheck password, form.is_valid() still get false.

ARJhe commented 4 years ago

Solution

  1. We did not match the restriction of validation.
    - Your password can’t be too similar to your other personal information.
    - Your password must contain at least 8 characters.
    - Your password can’t be a commonly used password.
    - Your password can’t be entirely numeric.
  2. We did not save it so that db won't store this record.
    def register(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            messages.success(request, f'Account created for {username}!')
            return redirect('blog_home')
    else:
        form = UserCreationForm()
    return render(request, 'users/register.html', {'form': form})