Django style multiple apps with web.py not working

半世苍凉 提交于 2019-12-13 00:37:42

问题


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:

  1. Keep wiki.py, and blog.py as specified in the example
  2. don't bother with delegate.py hack: it's no longer needed.
  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!