【问题标题】:how to include images,scripts that are in default folder of views in web2py如何在 web2py 中包含默认视图文件夹中的图像、脚本
【发布时间】:2016-03-26 00:01:58
【问题描述】:

我在默认的视图文件夹中有一张图片作为下面链接中的示例 (http://127.0.0.1:8000/cooking_recipes/default/images/nav-logo.png) 甚至是同一个文件夹中的一些脚本。那是因为我正在为我的网站使用现成的模板。那么我怎么能说 web2py 那些只是图像和脚本而不是 html 视图? 我发现 web2py 将它们视为视图并返回带有源代码的 html 页面 查看源代码:http://127.0.0.1:8000/cooking_recipes/default/images/nav-logo.png

<html><body><h1>invalid function (default/images)</h1></body></html>

【问题讨论】:

    标签: web2py web2py-modules


    【解决方案1】:

    静态资源应放在应用程序的 /static 文件夹中(您可能希望将图像放在 /static/images 中,将脚本放在 /static/js 中)。然后,您将使用 URL() 帮助器生成 URL:

    URL('static', 'images/nav-logo.png')
    

    【讨论】:

      猜你喜欢
      • 2014-08-24
      • 2013-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多