DEV Community

Discussion on: How to build a Django web app from scratch (tutorial)[2024 revised]

Collapse
 
codebyline profile image
Yumei Leventhal

I got the app set up and it looks great on my laptop. So I followed your instructions to deploy it on Heroku (which I never was able to figure out.) It took some effort --'favicon.ico' kept crashing the app and I ended up removing the reference to it. The app finally runs on Heroku. However, the images wouldn't show up. I duplicated the images in various possible folders just in case they were in the wrong place--but that didn't make any difference. I don't mean to have you spend time on this, but I am curious whether this is related to how Heroku operates. And, since the Recipe model is set up to receive uploaded images, so short of modifying the model, external images (from the web) can't be easily linked, can it? : frozen-fjord-60733.herokuapp.com/

Thread Thread
 
vladyslavnua profile image
vladyslav nykoliuk • Edited

Hi! So sorry for the delay in reply. I just checked your website it looks like you fixed it and it looks great! For anyone seeing this in future reference - a few possible scenarios:

  1. A static/media root directory error

Solution: Check how you're setting the STATIC_ROOT and MEDIA_ROOT

  1. Whitenoise wasn't properly installed, or saved to requirements

Solution: pip install whitenoise && pip freeze > requirements.txt

To answer your question about external images, the only way I know of referencing an external image by url would be to add another optional field and request that url for the image. A quick example can be seen over on Stack Overflow.

P.S. There seems to be a Markdown glitch for my comment where it doesn't change the second answer to number 2. Goes to show edge cases always exist :) πŸ˜‚

Thread Thread
 
codebyline profile image
Yumei Leventhal • Edited

Thanks for looking into it! I finally figured it out this morning. Just like you said, the issue was related to how the static and media directories were set up. Whitenoise was set up exactly as directed (and works seamlessly). What I ended up doing was deleting all the images from all the static and media folders, modified the path in settings. The app works, though I don't know why. I posted on Stackoverflow hoping to get some explanation, as I've never understood completely how to set up static files aside from copy and paste. So this is my chance to get it sorted it out.

Thread Thread
 
vladyslavnua profile image
vladyslav nykoliuk

ahh gotcha. Yup, I remember I actually tried to answer it on there too :)