I just product my site using Heroku and I got a odd problem with my media images broken. Here is my site structure on Heroku.
-- -- app -- manage.py -- mysite -- settings -- __init__.py -- base.py -- production.py -- static -- media -- product -- images -- -- static_dirs -- static_root
In my app/mysite/settings/ init.py
from .base import * try: from .local import * live = False except: live = True if live: from .production import *
and in my base.py
import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) STATIC_URL = '/static/' MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media') STATIC_ROOT = os.path.join(BASE_DIR, 'static', 'static_root') STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static', 'static_dirs'), ) TEMPLATE_DIRS = ( os.path.join(BASE_DIR, 'templates'), )
and in my production.py, I annotated as below.
# Static asset configuration # import os # BASE_DIR = os.path.dirname(os.path.abspath(__file__)) # STATIC_ROOT = 'staticfiles' # STATIC_URL = '/static/' # STATICFILES_DIRS = ( # os.path.join(BASE_DIR, 'static'), # )
Finally, I ran server and I got still broken image shown on my page. When I look the image carefully through "google inspect element",I can still see the probably right path as below.
<img class="img-responsive" src="/media/products/images/aws.png">
But when I see my /static/media/products/images/ folder, there were images created on development statge only, not the images I just created on production site. (aws.png)
As still beginner for django development, It is a tough to find answer even after few hour's googling.
Thanks always.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2f1eb33e-c1c0-417f-8665-b8f239540f4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment