On 9 February 2010 16:47, harryos <[email protected]> wrote:
> hi
> In my login_view I am redirecting to an archive page as below
>
> def login_view(request):
>        if request.method=='POST':
>                username=request.POST['username']
>                password=request.POST['password']
>                user = authenticate(username=username, password=password)
>                if user is not None and user.is_active:
>                        login(request, user)
>                        return redirect('myapp_archive_index')#default page
>                else:
>                        return render_to_response('myapp/login.html')
>        else:
>                return render_to_response('myapp/login.html')
>
> In login template for I am using the hidden field 'next'
>
> ...
> <input type="submit" value="login" />
>        <input type="hidden" name="next" value="{{next|escape}}" />
>
> I have given the LOGIN_URL as '/myapp/login/and in urlconf  set this
> to the above login_view method .
> url(r'^','myapp.views.login_view',name='myapp_login'),
>
> Also I have many views to list the entries belonging to an year,month
> etc..All of them have @login_required .
> eg:
> @login_required
> def entry_archive_year(request,year,month):
>        ....
>        return render_to_response('myapp/archive_month.html',somedict)
>
>
> Now if I try to access /myapp/entries/1999/jan/ ,I will get the login
> page .The url on browser search field is /myapp/login/?next=/myapp/
> entries/1999/jan/.If I login correctly ,I would like the page to go
> to /entries/1999/jan/  and not to the 'myapp_archive_index' page I
> provided in the login_view method.Is there a way to redirect to the
> value pointed to by this  'next'?
>
> thanks
> harry
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

Seems to me you done all that work just to redirect a user to your URL
after login?
You can use LOGIN_REDIRECT_URL [1] setting for this.

This way djangos auth login does all the work and redirects user on
successful login to URL set with LOGIN_REDIRECT_URL

[1] http://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url

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

Reply via email to