Hi all, not exactly a django question but here goes... I'm trying to
implement a decorator with one positional argument and one keyword
argument. My wrapper function gets the positional argument just fine
but the keyword argument throws an error "NameError: name 'as_string'
is not defined."
Code i
Chris
-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On
Behalf Of cootetom
Sent: 04 April 2011 15:31
To: Django users
Subject: Python Decorators
Hi all, not exactly a django question but here goes... I'm trying to
implement a decorator
Your code looks perfect. Following does print 'True'.
def widget(widget_switch, as_string=False):
def decorator(func):
def wrapper(*args, **kwargs):
# logic in here can access the value of 'widget_switch'
but 'as_string' is not defined?
print as_string
Yeah it's really odd. Since I posted I did the test that you've just
shown and it's works fine. As soon as I put the same decorator on a
django view function the as_string parameter is not defined in the
wrapper. It's baffled me!
On Apr 6, 10:48 am, Jonathan S wrote:
> Your code looks perfect.
4 matches
Mail list logo