简体   繁体   English

为什么我在 Heroku 部署上使用 Django 管理员上传的动态图像不显示?

[英]Why do dynamic images I uploaded using Django admin on a Heroku deployment not showing up?

I have an e-commerce Django website hosted in Heroku (free acc).我有一个电子商务 Django 网站托管在 Heroku (免费acc)。 I dynamically upload the image and price through the Django admin page.我通过 Django 管理页面动态上传图片和价格。 The images were showing up for one day, but from the next day, I am getting an "image not found (404)" error.图像显示了一天,但从第二天开始,我收到“找不到图像(404)”错误。 What's the reason for this error?这个错误的原因是什么?

Failed to load resource: the server responded with a status of 404 (Not Found)加载资源失败:服务器响应状态为 404(未找到)

You can't save (persistantly) media files into Heroku's local filesystem.您不能(永久)将媒体文件保存到 Heroku 的本地文件系统中。

The Heroku filesystem is ephemeral - that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted. Heroku 文件系统是短暂的 - 这意味着在测功机运行时对文件系统的任何更改只会持续到该测功机关闭或重新启动。 Each dyno boots with a clean copy of the filesystem from the most recent deploy.每个测功机都使用最新部署的文件系统的干净副本启动。 This is similar to how many container based systems, such as Docker, operate.这类似于运行了多少基于容器的系统,例如 Docker。

In addition, under normal operations dynos will restart every day in a process known as "Cycling" .此外,在正常操作下,dynos 每天都会在一个称为“循环”的过程中重新启动。

These two facts mean that the filesystem on Heroku is not suitable for persistent storage of data.这两个事实意味着 Heroku 上的文件系统不适合持久存储数据。 In cases where you need to store data we recommend using a database addon such as Postgres (for data) or a dedicated file storage service such as AWS S3 (for static files).如果您需要存储数据,我们建议使用 Postgres(用于数据)等数据库插件或 AWS S3(用于 static 文件)等专用文件存储服务。 If you don't want to set up an account with AWS to create an S3 bucket we also have addons here that handle storage and processing of static assets https://elements.heroku.com/addons如果您不想使用 AWS 设置帐户来创建 S3 存储桶,我们这里还有用于处理 static 资产的存储和处理的插件https://elements.Z3115FB34DFCB5BA8AA049707C596B7

Reference: https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted参考: https://help.heroku.com/K1PPS2WM/why-are-my-file-uploads-missing-deleted

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

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