0

Currently, I have been having issues with getting my static and media to work with django on heroku. My static is finally working, but my media won't, and this is my first in any sort of production environment, so I'm not sure if it is done correctly. My media files will work after an upload, however they no longer work once I edit something unrelated and try to push it to heroku typing:

git add .
git commit -m "changes"
git push heroku master

So after I update my heroku app, a user would have to re-add their media files in order for them to work every time I do an update. As far as the code I have so far:

#settings.py
DEBUG = False
MEDIA_ROOT = 'media'
MEDIA_URL = '/media/'
STATIC_ROOT = 'static'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    'static',
)

#urls.py
urlpatterns += staticfiles_urlpatterns()

if not settings.DEBUG:
    urlpatterns += patterns('',
        (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
        (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
    )

I'm pretty lost on what to do, and I have tried several different changes to my urls and settings without any luck. I have read other posts and tried them, I've read the docs, and I still don't really understand unfortunately. Everything was working fine in development, but I had different code for my project in development under my settings. Any help would be greatly appreciated.

EDIT

So after more digging, I decided to give Amazon S3 a try for handling my media files. I'm still not really sure how uploading files to S3 works, but I already created a S3 bucket and set my heroku settings (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, S3_BUCKET_NAME). I am still unsure of what my media and static settings should look like. If anyone can point me in the right direction, I would really appreciate it.

GetItDone
  • 566
  • 7
  • 22

1 Answers1

0

Ok so I finally got things working the way they should after a lot of banging my head against the wall. I am now using Amazon S3 for my static and media files (partially thanks to this post, and the most helpful post for me in getting things set up correctly was here. If you are using heroku, you probably want to look into using S3 for static and media files. Yes, it is something else you have to try to configure and integrate, and no it is not free, but if you just push back you may find yourself using it in the end anyway, so save yourself some time. This was also helpful for separating static and media into separate dierctories.

Community
  • 1
  • 1
GetItDone
  • 566
  • 7
  • 22