1

我从 web2py 开始,我需要在我的视图文件中链接我的静态文件。

我正在尝试使用 URL() 助手来制作链接,但我无法正常工作......

我的应用程序被称为红色,我的控制器默认和我的功能索引。我的视图称为 index.html 并且位于默认文件夹中,当我转到该页面时,我正确地看到了视图,但我的 URL 都是错误的......

到目前为止,我尝试过:

URL('static', 'css/bootstrap.min.css')

回馈:“/static/css/bootstartp.css”

URL(a=request.application, args='static/css/bootstrap.css')

它给出了:“/default/red/static/css/bootstrap.min.css”

URL(r=request, arg='static/css/bootstrap.min.css')

它给出了:“/index/static/css/bootstrap.min.css”

URL('static/css/bootstrap.min.css')

它给出了:“/default/static/css/bootstrap.min.css”

URL(a=request.application, c='static/css/bootstrap.min.css', f='')

它给出了:“/red/red/static/css/bootstrap.min.css”

我可能尝试了更多但没有成功...

我的索引函数只返回 dict()。

还有我的路由器:

routers = dict(

    # base router
    BASE = dict(
        applications = ['red', 'admin'],
        default_application = 'red',
        default_controller = 'default',
        default_function = 'index',
        map_static = True
    )
)

我认为说我正在谷歌应用引擎上测试它也很重要。

我想得到“/red/static/css/bootstrap.min.css”。

4

3 回答 3

1

我希望你想在你的视图中链接 css 文件。你可以通过两种方式做到这一点。

1.在控制器文件中(在 index() 中:)

response.files.append(URL(request.application,'static/css','bootstrap.min.css'))

您也可以在视图 (index.html) 中使用相同的命令:

{{response.files.append(URL(request.application,'static/css','bootstrap.min.css'))}}

2.在视图(index.html)中你可以提到正常的css链接。

<LINK rel="stylesheet" type="text/css" href="{{=URL('static/css','bootstrap.min.css')}}">

如果您想为整个应用程序链接此文件。然后在 layout.html 页面中提及上述行。

于 2012-07-25T09:27:05.110 回答
0

我找到了解决方案。

URL('static', 'css/bootstrap.min.css')

这行是正确的,但是我需要在路由器文件中关闭 map_static。

于 2012-07-25T09:16:13.477 回答
0

要获得“/red/static/css/bootstrap.min.css”

URL('red/static', 'css/bootstrap.min.css')
于 2012-07-13T21:08:37.627 回答