Hello,

I'm creating a template tag that will will allow session variables stored as
strings or
dict in a view to be available in its template. The syntax is:

{% session_value [view_name] [session_variable] [arg] %}

But at the moment I don't know how I can get Django to stop throwing name
errors
on variables/class names that are available. In my code, kwargs,
NoReverseMatch are all available, but
Django keeps reporting name errors on them.

Here's the snippet of the code at
https://github.com/charyorde/session_value/blob/master/templatetags/tags.py

bits = token.split_contents()
    if len(bits) < 2:
        raise TemplateSyntaxError("'%s' takes at least one argument"
                                  " (path to a view)" % bits[0])
    view_name = bits[1]
    session_variable = '' # or args - bits at session_variable
    kwargs = None # bits as argument to session_variable

    return SessionNode(view_name, session_variable, kwargs,
legacy_view_name=True)
session_value = register.tag(session_value)

class SessionNode(template.Node):
    def __init__(self, view_name, session_variable, kwargs=None,
legacy_view_name=True): #session_variable is used as args
        self.view_name = view_name
        self.session_variable = session_variable
        #self.args = args
        if kwargs is not None:
            self.kwargs = kwargs
        if not legacy_view_name:
            self.legacy_view_name = legacy_view_name

I will like to know what I'm doing wrong. How do I prevent these constant
name errors whenever the
template tag is registered?

Thanks
-- 
Odeyemi 'Kayode O.
http://www.sinati.com. t: @charyorde

-- 
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