gpt4 book ai didi

python - 如何在 Pylons 中设置默认页面?

转载 作者:行者123 更新时间:2023-11-28 22:07:16 25 4
gpt4 key购买 nike

我创建了一个新的 Pylons 应用程序并添加了一个带有模板(“index.mako”)的 Controller (“main.py”)。现在 URL http://myserver/main/index 起作用了。如何将其设为默认页面,即。当我浏览到 http://myserver/ 时返回的那个?

我已经在 routing.py 中添加了默认路由:

def make_map():
"""Create, configure and return the routes Mapper"""
map = Mapper(directory=config['pylons.paths']['controllers'],
always_scan=config['debug'])
map.minimization = False

# The ErrorController route (handles 404/500 error pages); it should
# likely stay at the top, ensuring it can always be resolved
map.connect('/error/{action}', controller='error')
map.connect('/error/{action}/{id}', controller='error')

# CUSTOM ROUTES HERE

map.connect('', controller='main', action='index')
map.connect('/{controller}/{action}')
map.connect('/{controller}/{action}/{id}')

return map

在对Default route doesn't work 的回答之后,我还删除了public 目录的内容(favicon.ico 除外)。现在我只收到错误 404。

我还需要做什么才能让这样一个基本的东西发挥作用?

最佳答案

试试这个:map.connect('/', controller='main', action='index')

关于python - 如何在 Pylons 中设置默认页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2406630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com