Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.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_Routes_Cherrypy_Mako - Fatal编程技术网

Python 在CherryPy中参数化url

Python 在CherryPy中参数化url,python,routes,cherrypy,mako,Python,Routes,Cherrypy,Mako,我有一个根对象,它映射到/ 它包含一个图表,单击其中的一行,用户将连接到另一个页面饼图 在饼图中,有两个函数采用相同的参数 def submit_data(self, wf_id, run_id, run_desc, day) 及 我希望将url映射为这样一种方式:当用户单击一行时,对应于该行的值被传递到链接地址 例如,如果该行对应于值wf_id=1、run_id=1、run_desc=1、day=2014-05-20,则单击该行可将用户连接到类似于/pie/1/1/2014-05-20或类似

我有一个根对象,它映射到/

它包含一个图表,单击其中的一行,用户将连接到另一个页面饼图

在饼图中,有两个函数采用相同的参数

def submit_data(self, wf_id, run_id, run_desc, day)

我希望将url映射为这样一种方式:当用户单击一行时,对应于该行的值被传递到链接地址

例如,如果该行对应于值wf_id=1、run_id=1、run_desc=1、day=2014-05-20,则单击该行可将用户连接到类似于/pie/1/1/2014-05-20或类似的内容,并将这些值传递到用于pie的html模板

我该怎么做

目前,我正在使用RoutesDispatcher,并手动设置所有URL,但由于day参数可以接受任何值,这就不可能了


我正在使用Mako模板语言。

您需要这样的东西

@cherrypy.expose
def Pie(self, wf_id='', run_id='', run_desc='', day=''):
    if(wf_id == '' or run_id == '' or run_desc == '' or day=''):
        return """<a href='/pie/%s/%s/%s/%s'>click here</a>""" % (wf_id, run_id, run_desc, day)
    else:
    # update db

希望这有帮助

您在哪一方面遇到了问题-在Mako呈现模板时构造URL,或者在使用URL调用CherryPy应用程序时调度URL?
@cherrypy.expose
def Pie(self, wf_id='', run_id='', run_desc='', day=''):
    if(wf_id == '' or run_id == '' or run_desc == '' or day=''):
        return """<a href='/pie/%s/%s/%s/%s'>click here</a>""" % (wf_id, run_id, run_desc, day)
    else:
    # update db