为什么在Heroku部署中使用Django admin上传的动态图像没有显示? [英] Why do dynamic images I uploaded using Django admin on a Heroku deployment not showing up?

查看:126
本文介绍了为什么在Heroku部署中使用Django admin上传的动态图像没有显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Heroku(免费acc)托管了一个电子商务Django网站。我通过Django管理页面动态上传图像和价格。这些图像显示了一天,但是从第二天开始,我收到了未找到图像(404)。错误。该错误的原因是什么?

I have an e-commerce Django website hosted in Heroku (free acc). I dynamically upload the image and price through the Django admin page. The images were showing up for one day, but from the next day, I am getting an "image not found (404)" error. What's the reason for this error?


加载资源失败:服务器响应状态为404(未找到)

Failed to load resource: the server responded with a status of 404 (Not Found)


推荐答案

您不能(持久地)将媒体文件保存到Heroku的本地文件系统中。

You can't save (persistantly) media files into Heroku's local filesystem.


Heroku文件系统为短暂-这意味着在dyno运行时,仅对
的文件系统进行任何更改,直到该dyno关闭或重新启动
。每个dyno都会使用最新部署中的
文件系统的干净副本进行引导。这类似于运行Docker等基于
容器的系统的数量。

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. 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.

此外,在正常操作下,dynos会每天以已知的
进程重新启动。如骑自行车

In addition, under normal operations dynos will restart every day in a process known as "Cycling".

这些有两个事实意味着Heroku上的文件系统不适合
持久存储数据。如果您需要存储数据,我们建议您使用数据库插件,例如Postgres(用于数据)或
专用文件存储服务,例如AWS S3(用于静态文件)。如果
您不想在AWS上创建一个帐户来创建S3存储桶,我们
此处也有用于处理静态
资产的存储和处理的插件 https://elements.heroku.com/addons

These two facts mean that the filesystem on Heroku is not suitable for persistent storage of data. 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). 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

参考: https://help.heroku.com / K1PPS2WM /为什么我的文件上传缺失删除了

这篇关于为什么在Heroku部署中使用Django admin上传的动态图像没有显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆