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
On Jan 27, 11:57 am, Jonathan Nelson <[email protected]> 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 [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
-~----------~----~----~----~------~----~------~--~---