_wrapped_view() problems with method_decorator

913 views
Skip to first unread message

Aidan Fitzpatrick

unread,
Mar 13, 2010, 7:59:22 AM3/13/10
to django...@googlegroups.com
Hello

I've been happily running Django 1.1.1 for a good while. It's excellent. Being a perfectionist with a deadline, I've wanted to make use of part of someone else's app which is written against 1.2. So, no problem. I read the release notes, pulled down the beta. @login_required as a method decorator no longer works, it says, so use @method_decorator to wrap. Fine. After some fiddling I found the released beta 1 doesn't have this method, so I pulled the head from SVN, and that has it. All good. So I've updated @login_required to @method_decorator(login_required) and all of my decorated views work when they get hit directly. However, the one instance where I call a view from another view (I guess I probably shouldn't do this?) I can't get to work.

I've pasted in a simplified version of my code, before and after. I'd appreciate any suggestions. I've stripped out my fancy middleware, so there's nothing exciting going on behind the scenes.

== Django 1.1.1. Works fine:

def home(request):
    if True:       
        return dashboard(request)
    return render_to_response( 'promo/home.html', {}, context_instance=RequestContext(request))

@login_required
def dashboard(request):
return render_to_response( 'dashboard.html', {}, context_instance=RequestContext(request) )

== Django 1.2 SVN. Doesn't work:

def home(request):
    if True:       
        return dashboard(request)
    return render_to_response( 'promo/home.html', {}, context_instance=RequestContext(request))

@method_decorator(login_required)
def dashboard(request):
return render_to_response( 'dashboard.html', {}, context_instance=RequestContext(request) )

== 1.2 throws this:
c:\python26\lib\site-packages\django\core\handlers\base.py in get_response
100. response = callback(request, *callback_args, **callback_kwargs) ...

c:\my_local_path\promo\views.py in home
40. return dashboard(request) ...

c:\python26\lib\site-packages\django\utils\decorators.py in _wrapper
21. return decorator(bound_func)(*args, **kwargs) ...

TypeError: "_wrapped_view() takes at least 1 argument (0 given)"

Appreciate any pointers!

Best,
A

Karen Tracey

unread,
Mar 13, 2010, 9:13:13 AM3/13/10
to django...@googlegroups.com
On Sat, Mar 13, 2010 at 7:59 AM, Aidan Fitzpatrick <ai...@reincubate.com> wrote:

I've been happily running Django 1.1.1 for a good while. It's excellent. Being a perfectionist with a deadline, I've wanted to make use of part of someone else's app which is written against 1.2. So, no problem. I read the release notes, pulled down the beta. @login_required as a method decorator no longer works, it says, so use @method_decorator to wrap. Fine. After some fiddling I found the released beta 1 doesn't have this method, so I pulled the head from SVN, and that has it. All good. So I've updated @login_required to @method_decorator(login_required) and all of my decorated views work when they get hit directly. However, the one instance where I call a view from another view (I guess I probably shouldn't do this?) I can't get to work.


You only need to change the decorator you are using if you are wrapping methods. The code you show below is wrapping functions. The doc here: http://docs.djangoproject.com/en/dev/releases/1.2/#user-passes-test-login-required-and-permission-required clarifies which is which based on arguments taken by the wrapped function. Try without changing the decorator on the dashboard function.

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

Reply all
Reply to author
Forward
0 new messages