简体   繁体   English

显示的ico文件但未显示jpg / png,{%load staticfiles%}破坏了代码

[英]ico files displayed but not jpg/png, {% load staticfiles %} breaks the code

Can't make my app "see" images. 无法使我的应用“看到”图像。 Was able to use static files with Jinja2 but not Django. 能够与Jinja2一起使用静态文件,但不能与Django一起使用。 If I put my images directly in my main app directory, I can display favicon.ico when declare it in app.yaml like this: 如果我将图像直接放在主应用程序目录中,则可以在app.yaml中声明favicon.ico,如下所示:

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

But this declaration doesn't work for other file types: 但是此声明不适用于其他文件类型:

- url: /image\.jpg
  static_files: image.jpg
  upload: image\.jpg

Inserting {% load staticfiles %} into template breaks the code. 将{%load staticfiles%}插入模板会破坏代码。

This line is accepted but no image is displayed (unless I use favicon.ico) 接受此行,但不显示任何图像(除非我使用favicon.ico)

<img src="image.jpg" />

Any ideas? 有任何想法吗?

Your code is correct 您的密码是正确的

- url: /image\.jpg
  static_files: image.jpg
  upload: image\.jpg

and your images should be "visible" in static directory: 并且您的图片在静态目录中应该“可见”:

- url: /static
  static_dir: static

Just make sure that these declarations are before you reference by package name: 只需确保在使用包名称引用之前就声明了这些声明:

- url: .*
  script: your.app

In this case you won't need to {% load staticfiles %}. 在这种情况下,您无需{%load staticfiles%}。 But your 500 error could be because of using older django versions as before 1.4 it was {% load static %} 但是您的500错误可能是由于使用1.4之前的旧django版本造成的,它是{%load static%}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM