Reputation: 83
when i use the Django
{{ forms }}
the forms i rendered with the build in functionalities, if user submits and fields are invalid the invalid fields are cleaned but rest of the information in the form is not cleaned, this provides the user to change only the fileds where error is raised.
When i use HTML forms on submit if there is a error all the fields are cleaned and the user has to write all the information over again from scratch.
How can i accomplish the same fuctionality in a html form as in Django
{{ forms }}
Upvotes: 0
Views: 147
Reputation: 860
You have to define a form processing in the view. Example:
class UserLoginView(View):
def get(self, request):
# here we process GET request
def post(self, request):
form = AuthenticationForm(request, data=request.POST)
if form.is_valid():
# do something
else:
# save form with data as context, and render it
context = {'form': form}
return render(request, 'customers/login.html', context)
Upvotes: 2