Skip to content
Advertisement

reset form to initial data in invalid_form and display error in Django

I have a profile form that shows email, user name and first name. user only allowed to change first name field and the others are read only, if user change HTML value in email and username then submit it, it returns error but fill the fields with invalid value entered. I tried create a new instance of form and render it but it no longer shows the error. The thing I want is to reset invalid data then display the error.

forms.py

JavaScript

views.py

JavaScript

html page

JavaScript

Advertisement

Answer

After a few searches I found that I can address my issue by adding disabled=True attribute to my fields so if user try to change it database will ignore change and returns the initial value as it said in Django documentation

JavaScript
Advertisement