我有Grigsoft的比较副本!工具,任何人都可以告诉我如何使用它与Perforce源代码控制?
我正在尝试在CherryPy控制器类中设置一种简单的方法来装饰方法,这样如果用户尚未进行身份验证,则会将用户重定向到登录页面.我打算做一个基本的Python装饰器,但这里的答案建议我使用CherryPy自定义工具代替.所以我试图这样做,但我不能让它工作.这就是我所拥有的:
def authenticate():
user = cherrypy.session.get('user', None)
if not user:
raise cherrypy.HTTPRedirect('/?errMsg=Please%20log%20in%20first')
cherrypy.tools.authenticate = cherrypy.Tool('on_start_resource', authenticate)
Run Code Online (Sandbox Code Playgroud)
该/home页面是一个应限制为经过身份验证的用户的页面,因此我有:
@cherrypy.expose
@cherrypy.tools.authenticate
def home(self, **kwargs):
tmpl = TemplateDir.get_template('home.mako')
return tmpl.render()
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试启动我的网站时出现此错误:
Traceback (most recent call last):
File ".\example.py", line 3, in <module>
from controller.main import Root
File "C:\...\controller\main.py", line 9, in <module>
class Root(BaseModule):
File "C:\...\controller\main.py", line 19, in Root
@cherrypy.tools.authenticate
File "C:\Python26\lib\site-packages\cherrypy\_cptools.py", line 119, in
__call__ % self._name)
TypeError: The 'authenticate' Tool does not accept positional arguments; you …Run Code Online (Sandbox Code Playgroud) 为什么会出现此错误?我只是在数据集设计器中设置了一些默认值...第二次出现这种情况......
"自定义工具错误无法生成代码.抛出了类型'System.OutOfMemoryException'的异常"
custom-tools ×3
cherrypy ×1
compare ×1
customtool ×1
diff ×1
p4v ×1
perforce ×1
python ×1
session ×1