我正在根据我在B CherryPy上发现的内容开发一个应用程序。
如本例所示,有两个配置文件,server.cfg (又称“全局”)和app.cfg。
两个配置文件都加载在文件中:
# Update the global settings for the HTTP server and engine
cherrypy.config.update(os.path.join(self.conf_path, "server.cfg"))
# ...
# Our application
from webapp.app import Twiseless
webapp = Twisel
我使用cherrypy作为web服务器,在返回页面之前,我希望检查用户的登录状态。这适用于主应用程序类中的方法(在site.py中),但是当我在一个类中调用同一个修饰函数时(在一个单独的文件中),它会给出一个错误。
validate_user()是用作装饰器的函数。它要么将用户传递给该页面,要么将其发送到401个受限页面,作为cherrypy.Tool,如下所示:
from user import validate_user
cherrypy.tools.validate_user = cherrypy.Tool('before_handler', validate_user)
我正在尝试让虚拟主机在cherrypy 3.2.0中运行在python 3上:
#!/usr/bin/env python
import cherrypy
from cherrypy import expose
class Root(object):
@expose
def index(self):
return "I am the root vhost"
class Foo(object):
@expose
def index(self):
return "I am testingdomain