Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python CherryPy的URL生成器_Python_Cherrypy_Werkzeug - Fatal编程技术网

Python CherryPy的URL生成器

Python CherryPy的URL生成器,python,cherrypy,werkzeug,Python,Cherrypy,Werkzeug,在使用werkzeug作为web框架之后(它很棒而且简单,但不支持某些功能),我现在正在尝试cherrypy 现在,我在cherrypy中错过的是werkzeug使用修饰函数的名称构建URL(例如,模板中的链接)的优雅方式,如下所示: @expose('/archive/<int:year>/<int:month>') def archive(request, year, month): pass >>> url_for('archive',2

在使用werkzeug作为web框架之后(它很棒而且简单,但不支持某些功能),我现在正在尝试cherrypy

现在,我在cherrypy中错过的是werkzeug使用修饰函数的名称构建URL(例如,模板中的链接)的优雅方式,如下所示:

@expose('/archive/<int:year>/<int:month>')
def archive(request, year, month):
    pass

>>> url_for('archive',2010,04)
'/archive/2010/04'
@expose('/archive/'))
def存档(请求、年份、月份):
通过
>>>“档案”的url_,2010年4月
“/archive/2010/04”

我在cherrypy没有找到类似的方法,我错过了吗?

你没有错过。CherryPy在“暴露”装饰器中没有内置这种方法。但是,您可以在应用程序中使用内置的URL模板,它具有类似的URL模板语法。如果你想把它包装成像werkzeug那样的装饰器,我们希望看到代码粘贴在维基上。将该逻辑粘贴到RoutesDispatcher类本身的优点