【问题标题】:CSS mapping issue in Google App EngineGoogle App Engine 中的 CSS 映射问题
【发布时间】:2012-04-02 20:46:17
【问题描述】:

我正在为 Google App Engine 编写一个 python webapp 应用程序,但我在 URL 映射方面遇到了一些问题。出于某种原因,我们想将 index.html 文件放在另一个文件夹中(与 main.py 文件不在同一个文件夹中)。一切正常,除了我们无法访问我们的 CSS 文件。这是我的 app.yaml 文件:

application: testApp
version: 1
runtime: python27
api_version: 1
threadsafe: false

handlers: 

- url: /css
  static_dir: test/gui/css

- url: /(.*\.(gif|png|jpg|ico))
  static_files: test/\1
  upload: test/(.*\.(gif|png|jpg|ico))

- url: /game/.*
  script: game.app

- url: /.*
  script: main.app

libraries:
- name: jinja2
  version: latest

这是我在 main.py 中的 URL 映射:

app = webapp2.WSGIApplication([('/', MainHandler)
                            ], debug=True, config=config)

这是我的文件的结构:
main.py
/test/index.html
/test/gui/css/stylesheets.css /test/gui/images

我已经尝试在 Stackoverflow 中搜索和浏览帖子,但我还没有找到任何可行的解决方案。非常感谢您的帮助,谢谢!

【问题讨论】:

    标签: python css google-app-engine url-routing yaml


    【解决方案1】:

    您在 HTML 代码中访问 c​​ss 文件的语句是什么?它应该看起来像这样:

    <link rel="stylesheet" href="/css/css_file_1.css">
    

    【讨论】:

      【解决方案2】:

      尝试添加斜线:

      - url: /css/
        static_dir: test/gui/css
      

      【讨论】:

      • 感谢您的及时回复!我已经尝试了您的建议,但我仍然无法访问 css 文件(我收到 404 not found 错误)。
      猜你喜欢
      • 1970-01-01
      • 2011-09-08
      • 1970-01-01
      • 1970-01-01
      • 2014-01-18
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      • 2014-01-12
      相关资源
      最近更新 更多