“Some files get ‘Static file referenced by handler not found'”

huangapple go评论74阅读模式
英文:

Some files get "Static file referenced by handler not found"

问题

I'm deploying to google app engine with Python/Django.
我正在使用Python/Django部署到Google App Engine。

I store css files and images in automatically created Cloud Storage.
我将CSS文件和图像存储在自动创建的Cloud Storage中。

I can read css files, but not images.
我可以读取CSS文件,但无法读取图像。

I think that the path is not wrong because the css file can be read. I think that it is due to the specifications of App Engine, but I do not know the detailed cause.
我认为路径没有问题,因为可以读取CSS文件。我认为这是由于App Engine的规格,但我不知道具体原因。

Please support me.
请支持我。

Of course it works fine locally. It is a situation where an error occurs only in production.
当然,在本地运行正常。这只是在生产环境中出现错误的情况。

▼Version

Python 3.9.12
Python 3.9.12

Django 4.1.1
Django 4.1.1

▼Log(Cloud Storage)

Static file referenced by handler not found: staticfiles/img/example.png/
处理程序引用的静态文件未找到:staticfiles/img/example.png/

▼app.yaml

runtime: python39
runtime: python39

instance_class: F1
instance_class: F1

env: standard
env: standard

service: default
service: default

entrypoint: gunicorn -b :$PORT config.wsgi:application
entrypoint: gunicorn -b :$PORT config.wsgi:application

includes:

  • secrets/secret.yaml
    包括:
  • secrets/secret.yaml

handlers:

  • url: /static
    static_dir: staticfiles/
  • url: /.*
    secure: always
    script: auto
    处理程序:
  • url: /static
    static_dir: staticfiles/
  • url: /.*
    secure: always
    script: auto

▼folder

“Some files get ‘Static file referenced by handler not found'”

“Some files get ‘Static file referenced by handler not found'”

英文:

I'm deploying to google app engine with Python/Django.
I store css files and images in automatically created Cloud Storage.
I can read css files, but not images.

I think that the path is not wrong because the css file can be read. I think that it is due to the specifications of App Engine, but I do not know the detailed cause.
Please support me.

Of course it works fine locally. It is a situation where an error occurs only in production.

▼Version

Python 3.9.12

Django 4.1.1

▼Log(Cloud Storage)

Static file referenced by handler not found: staticfiles/img/example.png/

▼app.yaml

runtime: python39
instance_class: F1
env: standard
service: default

entrypoint: gunicorn -b :$PORT config.wsgi:application

includes:
 - secrets/secret.yaml

handlers:
- url: /static
  static_dir: staticfiles/
- url: /.*
  secure: always
  script: auto

▼folder

“Some files get ‘Static file referenced by handler not found'”

答案1

得分: 1

问题出在HTML中的一个拼写错误。

<img class="..." src={% static "img/example.png" %}/>


<img class="..." src={% static "img/example.png" %} />

似乎我忘了在文件名后面加一个空格,所以它无法在GCS中正确引用。

英文:

The problem was a typo in the HTML.

&lt;img class=&quot;...&quot; src={% static &quot;img/example.png&quot; %}/&gt;

&lt;img class=&quot;...&quot; src={% static &quot;img/example.png&quot; %} /&gt;

It seems that I forgot to put a space after the file name, so it could not be referenced correctly in GCS.

huangapple
  • 本文由 发表于 2023年4月4日 11:38:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75925332.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定