0

Am working with django 1.5.4 with python 2.7 I have tried to figure out what is the cause of this image to show like this view.py

def single(request,slug):
product = Product.objects.get(slug=slug)
images = product.productimage_set.all()
categories = product.category_set.all()

context = {
    "product":product,
    "categories":categories,
    "edit":True,
    "images":images,
}
return render_to_response("products/single.html", context, context_instance=RequestContext(request))

and the single.html

{% extends "base.html" %}
{% block content %}
<h1>{{ product }}</h1>
{% for abc in images %}
<img src="{{ MEDIA_URL }}{{ abc.image }}" />
{% endfor %}
<ul>
{% for category in categories %}
<li>{{ category }}</li>
{% endfor %}
</ul>

{% if edit %}
<a href="#">Edit this product</a>
{% endif %}
{% endblock %}

But it shows is this picture

please help out with this issue is the problem form code or ? models.py

class Product(models.Model):
user = models.ForeignKey(User,null=True,blank=True)
title = models.CharField(max_length=180)
description = models.CharField(max_length=500)
price = models.DecimalField(max_digits=20,decimal_places=2)
sale_price = models.DecimalField(max_digits=20,decimal_places=2,null=True,blank=True)
slug = models.SlugField()
order = models.IntegerField(default=0)
timestamp = models.DateTimeField(auto_now_add=True,auto_now=False)
updated = models.DateTimeField(auto_now_add=False,auto_now=True)
active = models.BooleanField(default=True)


def __unicode__(self):
    return str(self.title)

class Meta:
    ordering = ['-order']

class ProductImage(models.Model):
    product = models.ForeignKey(Product)
    image = models.ImageField(upload_to="products/image/")
    title = models.CharField(max_length=120,null=True,blank=True)
    featured_image = models.BooleanField(default=False)
    timestamp = models.DateTimeField(auto_now_add=True,auto_now=False)
    updated = models.DateTimeField(auto_now_add=False,auto_now=True)


def __unicode__(self):
    return str(self.title)
cipher
  • 373
  • 7
  • 20

1 Answers1

1

For django 1.5.4 you have to setting.py and edit MEDIA_ROOT

MEDIA_ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))),"static","media")

MEDIA_URL = '/media/' ###This depends on the location of your media files### As this was for the location of my files 

and on urls.py

url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root':settings.MEDIA_ROOT}),
cipher
  • 373
  • 7
  • 20