简体   繁体   English

将 Django 应用程序部署到 Heroku 时未加载图像

[英]Images not loading when deploying Django app to Heroku

I deployed my app to heroku: https://doggos-only.herokuapp.com/我将我的应用程序部署到 heroku: https://doggos-only.herokuapp.com/

The images on the Dog Images link work locally, but they do not work on the deployed version. Dog Images 链接上的图像在本地工作,但它们不适用于已部署的版本。 The only useful error I'm getting is: cj_eOAaboi.jpg:1 Failed to load resource: the server responded with a status of 404 (Not Found)我得到的唯一有用的错误是:cj_eOAaboi.jpg:1 无法加载资源:服务器响应状态为 404(未找到)

My best guess is that it has something to do with the file path, but I'm not sure.我最好的猜测是它与文件路径有关,但我不确定。 I've tried looking around the web for a solution but have been unable to find one.我尝试在 web 周围寻找解决方案,但一直找不到。 Looking for any help, here is the repo: https://github.com/jpchato/doggos_only_project寻求任何帮助,这里是回购: https://github.com/jpchato/doggos_only_project

I'm deploying from the deploy_branch in my repo.我正在从我的仓库中的 deploy_branch 进行部署。

That's because media files (Those files uploaded by the user) in heroku are not persistent, that means that after a certain time all the media will be erased.这是因为 heroku 中的媒体文件(用户上传的那些文件)不是持久的,这意味着在一定时间后所有媒体都会被擦除。

I strongly suggest you to use a media CDN like cloudinary or amazon s3.我强烈建议您使用像cloudinary或 amazon s3 这样的媒体 CDN。

I wrote a post on how to setup a media CDN with cloudinary for free and you can access it right here我写了一篇关于如何免费使用 cloudinary 设置媒体 CDN 的帖子,您可以在此处访问它

Django Tutorial: Set up Media files in Deployment for FREE Django 教程:免费在部署中设置媒体文件

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

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