2

Whenever I visit the path for an uploaded image in the admin, I get a 404. The image is successfully uploaded in the specified path but I don't know what URL structure to use to access the image. There is not URL structure specified yet for the image (that's what I want to know, or am I missing anything else?). Here are the details:

My models.py

class Product(models.Model):
    category = models.ForeignKey('CatalogCategory', related_name='products')
    name = models.CharField(max_length=300)
    slug = models.SlugField(max_length=150)
    description = models.ImageField(upload_to='product_photo', blank=True)
    manufacturer = models.CharField(max_length=300, blank=True)
    price_in_dollars = models.DecimalField(max_digits=6, decimal_places=2)

this is the error:

Request URL: http://localhost:8000/admin/products/product/1/product_photo/soy_candles.jpg/ product object with primary key u'1/product_photo/soy_candles.jpg' does not exist.

this is the dir struct

product_photo
products
->templates
->models.py
->views.py
->...
manage.py
settings.py
urls.py

EDIT I have not touched the details regarding the admin on the settings

yretuta
  • 7,963
  • 17
  • 80
  • 151
  • Django tries to parse the url as an primary key of a product object, because the image path is appended to the current page. Can you provide the code that displays the image? Do you use the url attribute on the image field? – Reiner Gerecke Feb 04 '11 at 02:05
  • 1
    Have you defined MEDIA_URL? What's its value? When displaying the image, Django will join the relative path of the image with the one defined in MEDIA_URL. If that is empty, the path becomes relative and could cause that error. – Reiner Gerecke Feb 04 '11 at 02:24
  • Same as https://stackoverflow.com/questions/14806289/django-error-page-not-found-404 – Jay M Jun 22 '17 at 10:25

1 Answers1

4

Your MEDIA_URL defines this.

You either have it defined to '' and the admin is generating a relative URL or you have it set to http://localhost:8000/admin/products/product/1/ which is unlikely :P

Yuji 'Tomita' Tomita
  • 115,817
  • 29
  • 282
  • 245