I have a Django project that has got an image field in the models.py. It works fine in the development environment but in the production environment, it leads to the page not found error when I save the object.
Here is my product model in models.py
class Product(models.Model):
PRODUCT_CHOICES = (
('Whisky', (
('BLENDED SCOTCH', 'BLENDED SCOTCH',),
('BOURBON WHISKIES', 'BOURBON WHISKIES',),
('IRISH WHISKIES', 'IRISH WHISKIES',),
('SINGLE MALT', 'SINGLE MALT',),
('TENESEE WHISKIES', 'TENESEE WHISKIES',),
)
),
('vodka', 'vodka',),
('Wine', (
('RED WINE', 'RED WINE',),
('WHITE WINE', 'WHITE WINE',),
('ROSE WINE', 'ROSE WINE',),
)
),
('Champagne', 'Champagne',),
('Brandy', 'Brandy',),
('Cognac', 'Cognac',),
('Beer', (
('CIDER', 'CIDER',),
('LAGER', 'LAGER',),
('MALT', 'MALT',),
('DRAUGHT', 'DRAUGHT',),
)
),
('Tequila', 'Tequila',),
('Rum', 'Rum',),
('Gin', 'Gin',),
('Liquer', 'Liquer',),
('Extras', 'Extras',),
)
product_type = models.CharField(max_length=255, choices=PRODUCT_CHOICES, default=None)
picture = models.ImageField(upload_to='uploads', height_field=None, default=None, width_field=None, max_length=None)
name = models.CharField(max_length=200, default=None)
capacity = models.CharField(max_length=200)
cash = models.DecimalField(max_digits=7, decimal_places=2)
digital = models.BooleanField(default=False, null=True, blank=False)
date_uploaded = models.DateTimeField(default=timezone.now)
def __str__(self):
return self.name
@property
def imageURL(self):
try:
url = self.picture.url
except:
url = ''
return url
I have also modified my settings.py correctly to serve media and static files while in production. And should i also consider absolute or relative path for upload to in picture = models.ImageField(upload_to='uploads',
? to be picture = models.ImageField(upload_to='home/uptowndrinks/public_html/uploads',
because i tried but still got the 404 error
STATIC_URL = '/static/'
MEDIA_ROOT='/home/uptowndrinks/public_html/uploads'
MEDIA_URL = '/uploads/'
STATICFILES_DIRS=[BASE_DIR + "/static",]
STATIC_ROOT='/home/uptowndrinks/public_html/static'
My static and media files settings in settings.py
Kindly help, I have really tried but I need your assistance