List Info

Thread: Redirect after login problem




Redirect after login problem
country flaguser name
United States
2007-09-29 21:16:20
I'm having some problems getting the "next"
variable to work in the
authentication module. After a user is logged in the page
is
redirected to /accounts/profile rather than being directed
to the
"next" variable.

I'm using the following code, anyone got any ideas what
could be
wrong?


views.py
login_required(redirect_field_name='/login/')
def index(request)

urls.py
# Login
(r'^hosting/login/$', 'django.contrib.auth.views.login',
{'template_name': 'hosting/login.html'})

settings.py
LOGIN_URL = '/hosting/login/



hosting/login.html
{% extends "base.html" %}

{% block content %}

{% if form.has_errors %}
<p>Your username and password didn't match. Please try
again.</p>
{% endif %}

<form method="post" action=".">
<table>
<tr><td><label
for="id_username">Username:</label></
td><td>{{ form.username }}</td></tr>
<tr><td><label
for="id_password">Password:</label></
td><td>{{ form.password }}</td></tr>
</table>

<input type="submit" value="login"
/>
<input type="hidden" name="next"
value="{}" />
</form>

{% endblock %}


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


Re: Redirect after login problem
user name
2007-09-30 00:02:17
Hi

> I'm using the following code, anyone got any ideas what
could be
> wrong?

> login_required(redirect_field_name='/login/')

My guess is, that it should be:

login_required(redirect_field_name='/hosting/login/')


> urls.py
> # Login
> (r'^hosting/login/$',
'django.contrib.auth.views.login',
> {'template_name': 'hosting/login.html'})

or in your urls, you should also include a redirection:
'^login/$' => '^hosting/login/$'

Hope that helps

Przemek
-- 
AIKIDO TANREN DOJO  -   Poland - Warsaw - Mokotow - Ursynow
- Natolin
info:   http://tanren.pl/  
phone:+48501516666   email:dojotanren.pl

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


Re: Redirect after login problem
user name
2007-09-30 00:19:44
On 9/29/07, Paddy Joy <paddyjoygmail.com> wrote:
> views.py
> login_required(redirect_field_name='/login/')
> def index(request)

You're using the 'redirect_field_name' argument
incorrectly.

The default value is 'next', which means Django will expect
something like this:

http://yoursite.com/accounts/login/?next=/some
_auth_required_page/

But when you change the value of 'redirect_field_name',
you're
changing the name of the *variable* Django looks for; in
other words,
you're changing the '?next' bit, not the
'/some_auth_required_page/'
bit. So if you pass 'redirect_field_name="foo"',
for example, Django
will look for something like

http://yoursite.com/accounts/login/?foo=/some_a
uth_required_page/

And NOT something like

http://y
oursite.com/accounts/login/?next=foo

See the documentation for details:

http://www.djangoproject.
com/documentation/authentication/#the-login-required-decorat
or

-- 
"Bureaucrat Conrad, you are technically correct -- the
best kind of correct."

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


Re: Redirect after login problem
user name
2007-09-30 00:19:44
On 9/29/07, Paddy Joy <paddyjoygmail.com> wrote:
> views.py
> login_required(redirect_field_name='/login/')
> def index(request)

You're using the 'redirect_field_name' argument
incorrectly.

The default value is 'next', which means Django will expect
something like this:

http://yoursite.com/accounts/login/?next=/some
_auth_required_page/

But when you change the value of 'redirect_field_name',
you're
changing the name of the *variable* Django looks for; in
other words,
you're changing the '?next' bit, not the
'/some_auth_required_page/'
bit. So if you pass 'redirect_field_name="foo"',
for example, Django
will look for something like

http://yoursite.com/accounts/login/?foo=/some_a
uth_required_page/

And NOT something like

http://y
oursite.com/accounts/login/?next=foo

See the documentation for details:

http://www.djangoproject.
com/documentation/authentication/#the-login-required-decorat
or

-- 
"Bureaucrat Conrad, you are technically correct -- the
best kind of correct."

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


Re: Redirect after login problem
country flaguser name
United States
2007-09-30 04:40:59
Thanks guys,

I didn't fully understand the meaning of
"redirect_field_name".

login_required() on it's own works as expected.

Paddy

On Sep 30, 3:19 pm, "James Bennett"
<ubernost...gmail.com> wrote:
> On 9/29/07, Paddy Joy <paddy...gmail.com> wrote:
>
> > views.py
> > login_required(redirect_field_name='/login/')
> > def index(request)
>
> You're using the 'redirect_field_name' argument
incorrectly.
>
> The default value is 'next', which means Django will
expect something like this:
>
> http://yoursite.com/accounts/login/?next=/some
_auth_required_page/
>
> But when you change the value of 'redirect_field_name',
you're
> changing the name of the *variable* Django looks for;
in other words,
> you're changing the '?next' bit, not the
'/some_auth_required_page/'
> bit. So if you pass
'redirect_field_name="foo"', for example, Django
> will look for something like
>
> http://yoursite.com/accounts/login/?foo=/some_a
uth_required_page/
>
> And NOT something like
>
> http://y
oursite.com/accounts/login/?next=foo
>
> See the documentation for details:
>
> http://www.djangoproject.com/documentati
on/authentication/#the-login-...
>
> --
> "Bureaucrat Conrad, you are technically correct --
the best kind of correct."


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


[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )