broken image on my django production site. Why is it?

54 views
Skip to first unread message

rdyact

unread,
Nov 1, 2014, 10:51:42 AM11/1/14
to django...@googlegroups.com

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.



Kakar Nyori

unread,
Nov 2, 2014, 10:14:31 AM11/2/14
to django...@googlegroups.com
I think, you should add "static"/ in your html:

<img class="img-responsive" src="static/media/products/images/aws.png">

Or else change your directory settings.


--
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...@googlegroups.com.
To post to this group, send email to django...@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.

Collin Anderson

unread,
Nov 2, 2014, 8:46:36 PM11/2/14
to django...@googlegroups.com
Hello,

You may need to install something like dj-static to serve your files.

Collin

Reply all
Reply to author
Forward
0 new messages