Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » logout_then_login - how to alter login_url [RSS Feed]

#1 Dec. 15, 2008 22:37:50

r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

logout_then_login - how to alter login_url


quote from official docs about logout_then_login view: "login_url: The
URL of the login page to redirect to. This will default to
settings.LOGIN_URL if not supplied"
How to supply alternative login_url?

I add logout url to urls.py:
url(r'^accounts/logout/
$','django.contrib.auth.views.logout_then_login',name='logout'),

Then I'd like to redirect user to my custom page after logout succeed,
how could I do that?
{% url logout login_url="/my/custom/path" %} doesn't do the job, I
catch error in reverse function.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#2 Dec. 16, 2008 01:16:58

Malcolm T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

logout_then_login - how to alter login_url


On Mon, 2008-12-15 at 14:37 -0800, redbaron wrote:
> quote from official docs about logout_then_login view: "login_url: The
> URL of the login page to redirect to. This will default to
> settings.LOGIN_URL if not supplied"
> How to supply alternative login_url?

If you look at the function signature for logout_then_login(), in
django/contrib/auth/views.py, you'll see that it accepts a login_url
parameter.

>
> I add logout url to urls.py:
> url(r'^accounts/logout/
> $','django.contrib.auth.views.logout_then_login',name='logout'),
>
> Then I'd like to redirect user to my custom page after logout succeed,
> how could I do that?
> {% url logout login_url="/my/custom/path" %} doesn't do the job, I
> catch error in reverse function.

The parameters passed via the "url" template tag are parameters that are
captured by the regular expression for that URL pattern. Your pattern,
in this case, is "accounts/logout/", which has no variable pieces --
that is, the reg-ex has no capturing groups. That's a good thing, since
it's not really something the user is ever going to control -- there's
precisely one way to logout.

However, if you want to pass some extra information to the
logout_then_login function, look at the third argument in the url() call
-- the dictionary of extra parameters. You can set up the login_url
parameter there.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#3 Dec. 16, 2008 07:54:46

r.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

logout_then_login - how to alter login_url


> However, if you want to pass some extra information to the
> logout_then_login function, look at the third argument in the url() call
> -- the dictionary of extra parameters. You can set up the login_url
> parameter there.

hardcoding login_url is not the way I prefer to go. I supposed there
is some solution to pass login_url dynamically, but it's impossible as
I can see.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#4 Dec. 17, 2008 01:38:59

Malcolm T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

logout_then_login - how to alter login_url


On Mon, 2008-12-15 at 23:54 -0800, redbaron wrote:
>
> > However, if you want to pass some extra information to the
> > logout_then_login function, look at the third argument in the url() call
> > -- the dictionary of extra parameters. You can set up the login_url
> > parameter there.
>
> hardcoding login_url is not the way I prefer to go. I supposed there
> is some solution to pass login_url dynamically, but it's impossible as
> I can see.

This is a really simple problem: the URL tells you which view to call,
and each different login_url value means essentially a different view,
or at least a different parameter to pass to the same view. So either
you need to put the variable information in the URL itself, or you need
a different view each time that is a wrapper to call logout_then_login
with the correct login_url parameter. Since each URL will be different
in this second situation anyway, it's just a different version of case 1
-- perhaps the view has to convert the parameter in the URL to the real
login_url value or something.

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en-~----------~----~----~----~------~----~------~--~---

Offline

#5 April 17, 2017 23:12:30

Trustkef
Registered: 2017-04-14
Posts: 5
Reputation: +  0  -
Profile   Send e-mail  

logout_then_login - how to alter login_url

This post is being moderated

Offline

#6 June 20, 2017 14:21:29

AlexVoronPa
Registered: 2017-06-19
Posts: 1
Reputation: +  0  -
Profile   Send e-mail  

logout_then_login - how to alter login_url

This post is being moderated

Offline

#7 Aug. 7, 2017 15:17:06

AlexEnox
Registered: 2017-08-05
Posts: 1
Reputation: +  0  -
Profile   Send e-mail  

logout_then_login - how to alter login_url

This post is being moderated

Offline

  • Root
  • » Django
  • » logout_then_login - how to alter login_url [RSS Feed]

Board footer

Moderator control

Enjoy the 21st of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support