Python 如何在Mako的cherrypy配置工具中指定模板目录?

Python 如何在Mako的cherrypy配置工具中指定模板目录?,python,cherrypy,Python,Cherrypy,我正试着用这个 它说我需要两个配置选项 tools.mako.collection_size = 500 tools.mako.directories = "path/to/templates" 我在哪里指定这些选项以及如何指定这些选项?是一个很好的起点是一个很好的起点在CherryPy中有两种常见的配置方法。如果您没有指定任何配置设置,那么您将对所有内容使用默认值,并且您将在启动cherrypy应用程序时看到一条警告,说明配置为空 第一个选项是读取配置文件。这是这样做的: include

我正试着用这个

它说我需要两个配置选项

tools.mako.collection_size = 500
tools.mako.directories = "path/to/templates"

我在哪里指定这些选项以及如何指定这些选项?

是一个很好的起点

是一个很好的起点

在CherryPy中有两种常见的配置方法。如果您没有指定任何配置设置,那么您将对所有内容使用默认值,并且您将在启动cherrypy应用程序时看到一条警告,说明配置为空

第一个选项是读取配置文件。这是这样做的:

include cherrypy
include os.path

# Create your application / page handlers here

if __name__ == '__main__':
    global_conf_file = os.path.join(os.path.dirname(__file__, 'server.conf'))
    cherrypy.config.update(global_conf_file)
    cherrypy.quickstart(Myapp(), config=global_config_file)
[global]
tools.mako.collection_size = 500
tools.mako.directories = 'path/to/templates'
include cherrypy

# Create your application / page handlers here

if __name__ == '__main__':
    my_config = {'/': {'tools.mako.collection_size': 500,
                       'tools.mako.directories': 'path/to/templates'}}

    cherrypy.quickstart(Myapp(), my_config)
这些行可以直接包含在配置文件中,并带有一个[全局]标题,因此整个文件如下所示:

include cherrypy
include os.path

# Create your application / page handlers here

if __name__ == '__main__':
    global_conf_file = os.path.join(os.path.dirname(__file__, 'server.conf'))
    cherrypy.config.update(global_conf_file)
    cherrypy.quickstart(Myapp(), config=global_config_file)
[global]
tools.mako.collection_size = 500
tools.mako.directories = 'path/to/templates'
include cherrypy

# Create your application / page handlers here

if __name__ == '__main__':
    my_config = {'/': {'tools.mako.collection_size': 500,
                       'tools.mako.directories': 'path/to/templates'}}

    cherrypy.quickstart(Myapp(), my_config)
如果不想将配置选项放入单独的文件中,可以将它们作为字典包含在python主模块中,例如:

include cherrypy
include os.path

# Create your application / page handlers here

if __name__ == '__main__':
    global_conf_file = os.path.join(os.path.dirname(__file__, 'server.conf'))
    cherrypy.config.update(global_conf_file)
    cherrypy.quickstart(Myapp(), config=global_config_file)
[global]
tools.mako.collection_size = 500
tools.mako.directories = 'path/to/templates'
include cherrypy

# Create your application / page handlers here

if __name__ == '__main__':
    my_config = {'/': {'tools.mako.collection_size': 500,
                       'tools.mako.directories': 'path/to/templates'}}

    cherrypy.quickstart(Myapp(), my_config)

在CherryPy中有两种常见的配置方法。如果您没有指定任何配置设置,那么您将对所有内容使用默认值,并且您将在启动cherrypy应用程序时看到一条警告,说明配置为空

第一个选项是读取配置文件。这是这样做的:

include cherrypy
include os.path

# Create your application / page handlers here

if __name__ == '__main__':
    global_conf_file = os.path.join(os.path.dirname(__file__, 'server.conf'))
    cherrypy.config.update(global_conf_file)
    cherrypy.quickstart(Myapp(), config=global_config_file)
[global]
tools.mako.collection_size = 500
tools.mako.directories = 'path/to/templates'
include cherrypy

# Create your application / page handlers here

if __name__ == '__main__':
    my_config = {'/': {'tools.mako.collection_size': 500,
                       'tools.mako.directories': 'path/to/templates'}}

    cherrypy.quickstart(Myapp(), my_config)
这些行可以直接包含在配置文件中,并带有一个[全局]标题,因此整个文件如下所示:

include cherrypy
include os.path

# Create your application / page handlers here

if __name__ == '__main__':
    global_conf_file = os.path.join(os.path.dirname(__file__, 'server.conf'))
    cherrypy.config.update(global_conf_file)
    cherrypy.quickstart(Myapp(), config=global_config_file)
[global]
tools.mako.collection_size = 500
tools.mako.directories = 'path/to/templates'
include cherrypy

# Create your application / page handlers here

if __name__ == '__main__':
    my_config = {'/': {'tools.mako.collection_size': 500,
                       'tools.mako.directories': 'path/to/templates'}}

    cherrypy.quickstart(Myapp(), my_config)
如果不想将配置选项放入单独的文件中,可以将它们作为字典包含在python主模块中,例如:

include cherrypy
include os.path

# Create your application / page handlers here

if __name__ == '__main__':
    global_conf_file = os.path.join(os.path.dirname(__file__, 'server.conf'))
    cherrypy.config.update(global_conf_file)
    cherrypy.quickstart(Myapp(), config=global_config_file)
[global]
tools.mako.collection_size = 500
tools.mako.directories = 'path/to/templates'
include cherrypy

# Create your application / page handlers here

if __name__ == '__main__':
    my_config = {'/': {'tools.mako.collection_size': 500,
                       'tools.mako.directories': 'path/to/templates'}}

    cherrypy.quickstart(Myapp(), my_config)

您的编辑导致我的提要触发,我没有注意到答案或问题的年龄。哦,好吧。你的编辑触发了我的订阅源,我没有注意到答案或问题的年龄。哦,好吧。