alireza sadeghpour
alireza sadeghpour

Reputation: 689

How send data between views

I am writing a web based application that has a same login form in every page,so when user submit login form data sent to '/login/' page that corresponde view to this url will check the data has submitted and if input data was incorrect app must back to previews view and on that view in login form i must write a error that indicate that user entered incorrect data,so my question is how can i send data from login view to previous view(like home) that user entered incorrect data?

Upvotes: 0

Views: 54

Answers (2)

henrikstroem
henrikstroem

Reputation: 3068

In your login view, you use HttpResponseRedirect to send your user to your home view if the login is successful.

If the login is not successful, show the user the login form along with some error message that you can show the user if needed.

At the home view, you check if the user is logged in - if not, use HttpResponseRedirect to send them to the login view.

Upvotes: 1

madzohan
madzohan

Reputation: 11808

You can use sessions ... specifically messages framework

example from docs:

messages.add_message(request, CRITICAL, 'A serious error occurred.')

and related question Displaying Django Messages Framework Messages

Upvotes: 1

Related Questions