简体   繁体   English

Django ReactJS web 公共文件夹内的应用程序图标和图像未显示

[英]Django ReactJS web app Icons and Images Inside Public Folder Not Showing

I'm trying to deploy a small Django/ReactJS web app to heroku. I'm having an issue with the static images used as background and icons (the images folder is inside the public folder).我正在尝试将一个小型 Django/ReactJS web 应用程序部署到 heroku。我遇到了用作背景和图标的 static 图像的问题(图像文件夹位于公共文件夹内)。 The images do not show.图片不显示。 However, when I deploy only the frontend part as a static app, the images show correctly.但是,当我仅将前端部分部署为 static 应用程序时,图像会正确显示。 All the Django/ReactJS project I've been able to access so far have images imported inside App.js, it's not what I want to do.到目前为止,我能够访问的所有 Django/ReactJS 项目都在 App.js 中导入了图像,这不是我想要做的。 I want to use the urls to the images as for example:我想使用图片的网址,例如:

    background: "url(/images/somemage.png)"

Website without backend: https://base-apparel-coming-soon-react.herokuapp.com/没有后端的网站: https://base-apparel-coming-soon-react.herokuapp.com/

Website with backend: https://base-apparel-coming-soon-dr.herokuapp.com/后端网站: https://base-apparel-coming-soon-dr.herokuapp.com/

Git repository: https://github.com/.../base-apparel-coming-soon-DRF.../ Git 存储库: https://github.com/.../base-apparel-coming-soon-DRF.../

I figured out the solution incase it might help anyone, since I didn't find anything on the web.我想出了解决方案,因为它可能对任何人都有帮助,因为我在 web 上没有找到任何东西。

In wsgi.py Instead of writing:在 wsgi.py 而不是写:

    application = WhiteNoise(application, root=os.path.join(BASE_DIR, 'build/static'))

write

    application = WhiteNoise(application, root=os.path.join(BASE_DIR, 'build'))

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

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