5👍
✅
Since, the form is not validate in the else clause your form variable is overriden with a new form where it looses all of the errors
if request.method == 'POST':
form = RegistrationForm(request.POST)
if form.is_valid():
# If form has passed all validation checks then continue to save member.
user = User.objects.create_user(
username=form.cleaned_data['username'],
email=form.cleaned_data['email'],
password=form.cleaned_data['password']
)
user.save()
#member = User.get_profile()
#member.name = form.cleaned_data['name']
#member.save()
member = Member(
user=user,
name=form.cleaned_data['name']
)
member.save()
# Save is done redirect member to logged in page.
return HttpResponseRedirect('/profile')
return render_to_response('pageRegistration.html', context,context_instance=RequestContext(request))
2👍
Updated for the CBV world.
This is what was causing the equivalent error for me:
class CreateView(generic.CreateView): # or generic.UpdateView
def get_context_data(self, **kwargs):
context_data = super(CreateView, self).get_context_data(**kwargs)
# context_data['form'] = self.form_class # << this was the problematic override
- [Django]-Return data in httpresponse for ajax call in Deleteview in django?
- [Django]-How to save django FileField to user folder?
- [Django]-Django annotate multiple objects based on multiple fields on a M2M relationship
0👍
Perhaps the page is returning a new form every time it reloads. Check if the
context variable in views.py contains ‘form’ : form
👤Roy
- [Django]-Django ModelForm initial or custom field value
- [Django]-How to show list of foreign keys in Django admin?
- [Django]-How do I upload Pillow processed image to S3 on Django?
- [Django]-Django import client
- [Django]-Django 2.1+ bulk update records with the count of their related records?
Source:stackexchange.com