【问题标题】:Unable to add mapping to sub application in WebPy无法在 WebPy 中添加映射到子应用程序
【发布时间】:2012-11-22 11:06:24
【问题描述】:

我只是想明确一点,在 Windows 中,工作正常,但是当我尝试在我的 VPS 中部署此脚本时,它失败了。

这有点奇怪,因为如果我将映射添加到“mainwebapp”的主 Web 应用程序实例,它可以工作,但是每当我将它添加到任何子应用程序时,它都会显示为 webpy “Not Found”,我正在敲我的就因为这个而碰壁。

在 Windows 中,我有 Wamp 2.2。在我的 Vps 中,我有 CentOS 5、带有 uWsgi 的 nginx 以及来自我的 Windows 的相同 Python(2.7) 和 Webpy 版本。

我几乎可以肯定这是 nginx/uwsgi 的问题,因为当我在我的 Vps 中切换到 apache/mod_wsgi 时,它也可以在我的 Wamp 本地服务器中工作。

到目前为止,这是我一直在测试的代码,非常简单:

class subappcls:
     def GET(self):
          return "This will also be shown fine"


sub_mappings = (
     "/subpath", subappcls
)


#subclass web app
subwebapp = web.application( sub_mappings, globals() )



#mapped clas
class mapped_cls:
def GET(self):
     return "this mapped sub app will not be found"


#Here I add mappings:
subwebapp.add_mapping("/mapped_sub_path", mapped_cls



class appcls:
def GET(self):
     return "main app"



main_mappings = (
     "/subapp", subwebapp,
     "/app", appcls
)

mainwebapp = web.application( main_mappings, fvars=globals() )

class indexcls:
def GET(self):
     return "this will be shown just fine"

mainwebapp.add_mapping("/another",indexcls)


application = mainwebapp.wsgifunc()

当我访问时:

/subapp/subpath #会起作用

/subapp/mapped_sub_path #不起作用

这会很好用:

/应用程序

/另一个

这是 uwsgi 日志: * 在 [2012 年 12 月 4 日星期二 18:41:52] 开始 uWSGI 1.3(64 位) 使用版本编译:4.1.2 20080704(Red Hat 4.1.2-52)于 2012 年 11 月 24 日 02:21:31 操作系统:Linux-2.6.18-194.17.4.el5xen #1 SMP Mon Oct 25 16:36:31 EDT 2010 警告:你正在以 root 身份运行 uWSGI !!! (使用 --uid 标志) 您的进程数限制为 32832 你的内存页大小是 4096 字节 检测到的最大文件描述符数:1024 锁引擎:pthread 强大的互斥锁 uwsgi socket 0 绑定到 UNIX 地址 /tmp/app.sock fd 3 Python 版本:2.7.3(默认,2012 年 10 月 30 日,06:37:20)[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] Python 线程支持已禁用。您可以使用 --enable-threads *

启用它

编辑:我使用 --enable-threads 参数启用了线程,但也没有用。

提前致谢。

【问题讨论】:

    标签: python django web.py uwsgi


    【解决方案1】:

    问题似乎与重新加载器有关。如果在集成开发服务器中运行以下代码(使用命令 python code.py),则以下代码有效:

    import web
    
    
    web.config.debug = False  # turns off the reloader
    
    
    class subappcls:
        def GET(self):
            return "This will also be shown fine"
    
    sub_mappings = (
        "/subpath", subappcls
    )
    
    #subclass web app
    subwebapp = web.application(sub_mappings, globals())
    
    
    #mapped class
    class mapped_cls:
        def GET(self):
            return "this mapped sub app will not be found"
    
    
    #Here I add mappings:
    subwebapp.add_mapping("/mapped_sub_path", mapped_cls)
    
    
    class appcls:
        def GET(self):
            return "main app"
    
    
    main_mappings = (
        "/subapp", subwebapp,
        "/app", appcls,
    )
    
    mainwebapp = web.application(main_mappings, globals())
    
    
    class indexcls:
        def GET(self):
            return "this will be shown just fine"
    
    mainwebapp.add_mapping("/another", indexcls)
    
    
    if __name__ == "__main__":
        mainwebapp.run()
    else:
        application = mainwebapp.wsgifunc()
    

    运行卷曲:

    curl http://localhost:8080/subapp/mapped_sub_path
    this mapped sub app will not be found
    

    【讨论】:

    • 你真是个天才,我有多个子应用程序,我只是在主应用程序上关闭它,但对子应用程序没有,这真的是修复,非常感谢!!
    • 我没有在 uwsgi 上检查这个,但它应该可以工作。将 web.config.debug 设置为 False 将全局关闭所有应用程序堆栈的重新加载器。
    猜你喜欢
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 2013-07-26
    • 2021-04-18
    • 2021-11-06
    • 1970-01-01
    • 2018-10-01
    • 1970-01-01
    相关资源
    最近更新 更多