无法在WebPy中向子应用程序添加映射

2024-09-30 06:31:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我只想弄清楚,在windows环境下工作正常,但是当我试图在VPS中部署这个脚本时,它失败了。在

这有点奇怪,因为如果我添加一个映射到主web应用程序实例,它是“mainwebapp”,它可以工作,但每当我把它添加到任何子应用程序中时,它会显示为webpy“Not Found”,我就因为这个把头撞到墙上了。在

在windows中我有wamp2.2。在我的Vps中,我有centos5、nginx和uWsgi以及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#路径将不起作用

这很好:

/应用程序

/另一个

这是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周一,美国东部时间2010年10月25日16:36:31 警告:您正在以根用户身份运行uWSGI!!!(使用--uid标志) 你的进程数限制是32832 你的内存页大小是4096字节 检测到的最大文件描述符数:1024 锁引擎:pthread健壮互斥 绑定到UNIX地址/tmp的uwsgi套接字0/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参数启用了线程,但也没有工作。在

提前谢谢。在


Tags: self版本webapp应用程序getreturnwindows
1条回答
网友
1楼 · 发布于 2024-09-30 06:31:50

问题似乎出在重装机上。如果在integrated dev server中运行(使用命令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()

跑步卷曲:

^{pr2}$

相关问题 更多 >

    热门问题