add_mapping not functioning with reloader #163

Open
alexksikes opened this Issue Jul 4, 2012 · 2 comments

2 participants

@alexksikes
import web

urls = (
    '/hello', 'hello',    
)

class hello:    
    def GET(self):
        return 'hello world!'

class bye:
    def GET(self):
        return 'bye!'    

if __name__ == '__main__':
    #web.config.debug = False

    app = web.application(urls, fvars=globals())
    app.add_mapping('/bye', 'bye')

    # prints hello
    print app.request('/hello').data

    # not found unless web.config.debug = False 
    print app.request('/bye').data
@faruken

You could have a workaround by defining the urls inside ifmain. It works properly in that case.

import web

class hello:    
    def GET(self):
        return 'hello world!'

class bye:
    def GET(self):
        return 'bye!'    

if __name__ == '__main__':
    urls = (
        '/hello', 'hello',
    )

    web.config.debug = True

    app = web.application(urls, fvars=globals())
    app.add_mapping('/bye', 'bye')

    # prints hello
    print app.request('/hello').data

    # not found unless web.config.debug = False 
    print app.request('/bye').data
@alexksikes

Here is another by explicitely specifying fvars.

import web

urls = (
    '/hello', 'hello',    
)

class hello:    
    def GET(self):
        return 'hello world!'

class bye:
    def GET(self):
        return 'bye!'    

if __name__ == '__main__':
    #web.config.debug = False

    # keeping fvars=globals() won't do!
    #app = web.application(urls, fvars=globals())
    app = web.application(urls, dict(hello=hello))

    # explicitely specify fvars after adding mapping!
    app.add_mapping('/bye', 'bye')
    app.fvars['bye'] = bye

    # prints hello
    print app.request('/hello').data

    # prints bye regardless of web.config.debug = False 
    print app.request('/bye').data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment