Pritam
Pritam

Reputation: 97

How to change content if the page is requested from a specific url in django?

Say I have two pages one is example.com/login and another page is example.com/admin And when I put the credentials on the login page I get redirected to the admin page. Admin page has a logout button. If I press that button then it redirects me to the login page again.
What I exactly want to do is, I want to display a message "Login again" dynamically (I know how to display a message dynamically) but only when user gets redirected from the login page via admin panel.

How can I do that?

Upvotes: 0

Views: 125

Answers (1)

Simou
Simou

Reputation: 742

You can do that either by:

  1. Using Session: upon logout you set a variable in the session, that this user has been loged out.
    logout(request)
    request.session['logged_out'] = True
  1. Get parameter: add a parameter to the redirected login url, if you find that parameter show you message, if there is no parameter you don't have to show.
    redirect('login/?logged-out=True')

in both cases you have to check in your view, and add a a property to check with in your context.

Upvotes: 1

Related Questions