Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subapps in Web.py always return 405

Tags:

python

web.py

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?

like image 730
yrk Avatar asked Feb 02 '26 13:02

yrk


1 Answers

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"
like image 162
dersvenhesse Avatar answered Feb 05 '26 07:02

dersvenhesse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!