英文:
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
英文:
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
答案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.
<img class="..." src={% static "img/example.png" %}/>
↓
<img class="..." src={% static "img/example.png" %} />
It seems that I forgot to put a space after the file name, so it could not be referenced correctly in GCS.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论