【问题标题】:Google App Engine add image to page with static folderGoogle App Engine 将图像添加到带有静态文件夹的页面
【发布时间】:2014-07-17 08:55:40
【问题描述】:

我在页面中使用带有静态文件夹路径的图像时遇到问题。 这是我的 app.yaml

application: something
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /images
  static_dir: static/images

- url: /favicon.ico
  static_files: static/favicon.ico
  upload: static/favicon.ico

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.2"
- name: jinja2
  version: latest

我有模板、静态/图像、控制器(有 MainHandler.py)文件夹,在我的根目录中有 main.py 和 app.yaml 文件。在我的模板文件夹中,我有 index.html 文件,其中包含:

<div>
    <img src="images/fig1.jpg">
</div>

我的问题是当页面加载时我看不到我的 fig1.jpg 图片。

【问题讨论】:

    标签: python google-app-engine web2py


    【解决方案1】:

    这个页面的网址是什么?如果它看起来像一个子目录,那么您为图像使用的相对路径并未指向 images 路径。尝试更改为:

    <div>
        <img src="/images/fig1.jpg">
    </div>
    

    如果使用 Windows,则存在一个已知错误。见:

    Google App Engine: Won't serve static assets with below error:

    尝试将mime_type: "image/jpeg" 添加到您的图像处理程序,看看是否是原因。

    【讨论】:

    • 非常感谢@GAEfan,但它也不起作用。我正在本地机器上工作。
    猜你喜欢
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多