问题
I run the example in the tutorial Django style multiple apps with web.py, but it does not working. The following is error message:
Traceback (most recent call last):
File "run.py", line 11, in <module>
delegate.run(mapping)
File "/home/siongui/dev/test/delegate.py", line 31, in run
web.run(handler, {})
AttributeError: 'module' object has no attribute 'run'
My web.py version is 0.37. Is there any idea on how to fix this? Thanks. (subapp is not a option for me.)
回答1:
There is some addition for the application module in 0.3 (http://webpy.org/docs/0.3/)
Applications. How to map urls to python code paths.
- Basic app. Map regexes to classes.
- Auto app. Have webpy keep track of the urls based on class name.
- Subdir app. Host multiple apps based on the sub-directory.
- Subdomain app. Host multiple apps based on the subdomain.
Following this cookbook should get things to work.
http://webpy.org/cookbook/subapp
回答2:
It's even easier than the example provided at webpy.org.
Updating that Django style multiple apps example:
- Keep
wiki.py
, andblog.py
as specified in the example - don't bother with
delegate.py
hack: it's no longer needed. change
run.py
to:"""run.py""" import web import wiki import blog urls = ("/blog", blog.app_blog, "/wiki", wiki.app_wiki, "/(.*)", "index") class index: def GET(self, path): return "other: " + path app = web.application(urls, locals()) if __name__ == "__main__": app.run()
The key change is the urls specified in run.py
. If the second item is a string ("index"
in the above example) then web.py expects that to be a class to handle the matching url ("/(.*)"
in the example). This is the way webpy normally works.
However, if the second item is type application
(blog.app_blog
, for example), then the matching url (/blog
) isn't a regex, it's a prefix & all incoming requests matching that prefix are handed to the related application
(and the prefix is removed from the incoming request).
来源:https://stackoverflow.com/questions/17007882/django-style-multiple-apps-with-web-py-not-working