yrk
yrk

Reputation: 165

Subapps in Web.py always return 405

Well, this is in my code for the app.py

urls = (
    '/', 'Index',
    '/Test', 'module.test_module.test_app'
    )

my test_module.py

import web
urls = (
  "/(.*)", "Test"
)

class Test:
    def GET(self):
        return "HELLO"

test_app = web.application(urls, locals())

entering via Browser 0.0.0.0:8080/Test I get this in my console:

yanniks-mbp:page user$ python app.py
http://0.0.0.0:8080/
127.0.0.1:55914 - - [09/Jul/2014 22:47:43] "HTTP/1.1 GET /Test" - 405 Method Not Allowed

So my folder structure looks like this:

app.py
module (folder)
  |
  - __init__.py
  - test_module.py
  - other_files.py

I think I mess something up really bad with the imports or direct declaration in the URLs but I don't know what. Any ideas?

Upvotes: 3

Views: 156

Answers (1)

dersvenhesse
dersvenhesse

Reputation: 6414

You dont't need to run web.application in your test_module, you can directly refer to the class Test in your app.js.

app.py

import web

urls = (
    '/', 'Index',
    '/Test', 'module.test_module.Test'
)

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()

module/__init__.py

import test_module

module/test_module.py

class Test:
    def GET(self):
        return "HELLO"

Upvotes: 1

Related Questions