【问题标题】:How do I set a default page in Pylons?如何在 Pylons 中设置默认页面?
【发布时间】:2010-03-09 04:14:28
【问题描述】:

我创建了一个新的 Pylons 应用程序并添加了一个带有模板(“index.mako”)的控制器(“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

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

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

【问题讨论】:

    标签: python routes pylons


    【解决方案1】:

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

    【讨论】:

    • Pylons 使用路由,这些文档在开始使用路由时非常有用:routes.groovie.org/setting_up.html
    • 这行得通 - 谢谢!我可以发誓我在我复制的文件中看到了 '',而不是 '/'。
    【解决方案2】:

    您需要删除 public/index.html 文件才能使 / 路由规则起作用。否则直接送达。

    【讨论】:

      猜你喜欢
      • 2014-12-06
      • 2010-12-27
      • 2018-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多