On Tue, Nov 12, 2013 at 10:27 AM, pip <[email protected]> wrote:

> So I have:
>
> urls = (
>     "/example/(.+)", "example"
> )
>
>
> class example:
>     def GET(self, examplexxx):
>         if examplexxx:
>             #return "You requested examplexxx: %s" % examplexxx
>             try:
>                 return render.examplefolder.examplexxx()
>             except Exception, e:
>                 return e
>
>     def POST(self):
>         pass
>
> Well obviously it takes examplexxx literally, rather than using the actual
> value of examplexxx.
>
> How can I get around this?
>

Like with any Python object, you need to use getattr get an attribute by
name.

t = getattr(render.examplefolder, examplexxx)
return t()

I often used the following function in such cases.

def render_template(name, *a, **kw):
    t = render
    for k in name.split("/"):
        t = getattr(t, k)
    return t(*a, **kw)

class example:
    def GET(self, examplexxx):
        return render_template("examplefolder/" + examplexxx)

Anand

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to