On Tue, Jan 27, 2009 at 3:25 PM, Jonathan Nelson <iamelgri...@gmail.com>wrote:

>
> I just figured it out.
>
> Instead of using a decorator, I just used this:
> def myview(request, comment_id):
> ...if not request.user.is_authenticated():
> ......return HttpResponseRedirect('/login/?next=%s') % request.path
>

This is what the decorator is for, so that your do not have to put this code
in your view.

The redirect_field_name is used if you want to use a value other than 'next'
for the name of the query string parameter that holds the value to be
redirected to.  So, if I decorate a view with:

@login_required(redirect_field_name='martha')
def index(request, model_name):

and try to access that view (happens to be at /puzzles/) when not logged in,
I get redirected to (on my local testserver):

http://localhost:8000/accounts/login/?martha=/puzzles/

I doubt you really want to change redirect_field_name, it is not the name
but the value of the variable that you want to vary by view, and that is
what is automatically done by the @login_required decorator.  Just use it
with no parameters.

Karen


>
> On Jan 27, 11:57 am, Jonathan Nelson <iamelgri...@gmail.com> wrote:
> > I'm trying to decorate a view function with login_required.  I want
> > the user to be redirected to the current view after they log in.
> >
> > I'm trying:
> >
> > @login_required(redirect_field_name=request.path)
> > def myview(request, comment_id):
> > ....return render_to....
> >
> > but, I'm getting a "NameError: name 'request' is not defined".  I'm
> > assuming that's because the decorator doesn't have access to the
> > request object.  Is there a way to have access to that in the
> > decorator?  I can't create my url like this, either:
> >
> > @login_required(redirect_field_name='/myview/%s' %comment_id )
> > def myview(request, comment_id):
> > ....return render_to....
> >
> > because the decorator doesn't seem to have access to the post
> > variables.
> >
> > Any thoughts?
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to