Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Jillian S. Estrella (she/her)
Jillian S. Estrella (she/her)
15,720 Points

Whitenoise breaks ImageField references

Following along with Kenneth's "Deploying Django: PythonAnywhere" course, all goes well except that when using Whitenoise to serve static assets it breaks ImageField references. This I assume is because the database still points to my original media/images directory (where images are uploaded to by the Django Admin) and does not update to use the new staticfiles directory that Whitenoise sets up.

The question is how does one (properly) update the database to point to the new staticfiles directory?

Jillian S. Estrella (she/her)
Jillian S. Estrella (she/her)
15,720 Points

Also it seems that python manage.py collectstatic --settings=my_project.deploy_settings didn't copy ALL the image assets over, it only copied maybe half of them for some reason.

Jillian S. Estrella (she/her)
Jillian S. Estrella (she/her)
15,720 Points

my question is answered here:

http://stackoverflow.com/questions/31073322/serving-media-files-during-deployment-in-django-1-8

"'Media' files in Django are for runtime uploaded files. They will generally be stored with a corresponding db entry such as models.ImageField(upload_to='/photos') but that isn't necessarily so.

Your media setup is wrong, as you shouldn't be writing to a directory on the server anyway (this is what you are telling Django to do with MEDIA_ROOT = os.path.join(BASE_DIR, "media").

Most commonly you would instead use an S3 bucket for media."

And how to serve static and media assets from an S3 bucket is shown here:

https://www.caktusgroup.com/blog/2014/11/10/Using-Amazon-S3-to-store-your-Django-sites-static-and-media-files/