1👍
Your view function is wrong – you have to pass the invalid form to the context to get the error messages, ie:
def view_MainForm(request):
if request.method == 'POST' :
form_instance = form_MainForm(request.POST)
if form_instance.is_valid():
form_instance.save()
# here you should redirect to avoid
# re-submission of the form on page reload
# cf https://en.wikipedia.org/wiki/Post/Redirect/Get
return render(request,'done.html',{'text':form_instance.cleaned_data.get('email')})
else:
form_instance = form_MainForm()
context = {"form": form_instance}
return render(request,'main_form.html',context)
0👍
check this link to render error in your form https://docs.djangoproject.com/en/1.10/topics/forms/#rendering-form-error-messages , this will give an idea like why you are not able to save data.
when you are sending back the form it should be
context = {“form”: form_MainForm(request.POST)} , this will display the form submitted values
👤rsb
- Following button on site not working
- Efficient way to filter a hierarchical structure in Django?
- Django ForeignKey Works for Filter but not List Display
- Django unable to show webpage
- Models list as choices in a Model
Source:stackexchange.com