'Django forms not valid
I am using custom django forms. It seems that my form is not valid. I can't find the error. Could you help please??
signup.html`
Error Something went wrong! x<div class="container">
<div class="card center spacer">
<h1 class="title text-center">Register With</h1>
<div class="social-login">
<button class="social-btn">
<img class="icon" src="{% static 'helpus/images/icons/gmail.svg' %}" alt="gmail icon">
Gmail
</button>
<button class="social-btn">
<img class="icon" src="{% static 'helpus/images/icons/facebook.svg' %}" alt="gmail icon">
Facebook
</button>
</div>
<div class="text-center line form-divider">or</div>
<form method="POST" action= "." class="login-form spacer" id="signup-form">
{% csrf_token %}
<div class="input-group">
<img class="icon input-icon" src="{% static 'helpus/images/icons/profile-user.svg' %}" alt="">
{{form.username}}
</div>
<div class="input-group">
<img class="icon input-icon" src="{% static 'helpus/images/icons/envelope.png' %}" alt="">
{{form.email}}
</div>
<div class="input-group">
<img class="icon input-icon" src="{% static 'helpus/images/icons/key.svg' %}" alt="">
{{form.password1}}
</div>
<div class="input-group">
<img class="icon input-icon" src="{% static 'helpus/images/icons/key.svg' %}" alt="">
{{form.password2}}
</div>
<input type="submit" class="submit" value="Signup">
</form>
</div>
</div>
<div class="redirect">
Already have an account? <a href="login.html" class="link">Login</a>
<br><br>
<a href="forgot-password.html" class="link">Forgot password?</a>
</div>
def signup(request):
form = SignUpForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
password = form.cleaned_data.get('password1')
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
messages.success(request, "Registration successful." )
return redirect('./')
else:
print (form.errors)
form=SignUpForm()
messages.error(request, "Unsuccessful registration. Invalid information.")
context = {
'form': form
}
return render(request, 'helpus/signup.html', context)
HERE IS THE ERROR:
Thank you
`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|