Own stuff on web.ctx "disappearing" after reloading webpage

38 views
Skip to first unread message

Javier Barrio

unread,
Nov 18, 2012, 3:10:16 PM11/18/12
to we...@googlegroups.com
Hi,

I've been playing a little bit with the framework .I was trying to separate some stuff when I found something weird. Something that I am sure has an explanation. I did try this:

[main.py]
#!/usr/bin/env python
import web
render = web.template.render('templates/')
web.ctx.render = render
urls = (
        '/',    'core.home.home'
       )
if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()

[core/home.py]
import web

class home:
    def GET(self):
        i = web.input(name=None)
        return web.ctx.render.home(i.name) # here is the "problem"

[templates/home.html]
$def with (name)
$if name:
    I just wanted to say <em>hello</em> to $name.
$else:  
    <em>Hello</em> World!


The problem I am facing is that, when I launch ./main.py and browse to localhost:8080, the first time it shows up correctly and I can read 'hello world', but if I reload the page, it always shows me this error:

[ERROR on 2nd RELOAD]
127.0.0.1:39690 - - [18/Nov/2012 18:20:47] "HTTP/1.1 GET /" - 500 Internal Server Error
Traceback (most recent call last):
  File "/code/python/webpy/web/application.py", line 239, in process
    return self.handle()
  File "/code/python/webpy/web/application.py", line 230, in handle
    return self._delegate(fn, self.fvars, args)
  File "/code/python/webpy/web/application.py", line 420, in _delegate
    return handle_class(cls)
  File "/code/python/webpy/web/application.py", line 396, in handle_class
    return tocall(*args)
  File "/code/python/webpy/core/home.py", line 6, in GET
    return web.ctx.render.home(i.name)
AttributeError: 'ThreadedDict' object has no attribute 'render'

It's like if web.ctx was "losing" the 'render'. How is it possible that it works the first time I browse but not the next ones? I'm using 0.37.

Cheers.

Anand Chitipothu

unread,
Nov 18, 2012, 10:30:12 PM11/18/12
to webpy
On Mon, Nov 19, 2012 at 1:40 AM, Javier Barrio <jba...@jbarrio.com> wrote:
> Hi,
>
> I've been playing a little bit with the framework .I was trying to separate
> some stuff when I found something weird. Something that I am sure has an
> explanation. I did try this:
>
> [main.py]
> #!/usr/bin/env python
> import web
> render = web.template.render('templates/')
> web.ctx.render = render
> [...]

web.ctx is thread local context. It is meant for storing stuff that is
local to one request.

Anand
Reply all
Reply to author
Forward
0 new messages