[Answer]-Image upload through Django admin panel not working

1👍

MEDIA_URL is a url, not a file path. You need:

MEDIA_URL = "images/"

You also need to change the upload_to field, otherwise your images will go into /flipdiscountApp/images/images/.

You should also use the url property of the ImageField:

def get_image_url(self):
    """Method to return store image for admin panel"""
    return '<img src="%s" height="150" width="150"/>' % self.storeImage.url
get_image_url.allow_tags = True

I also changed your method name as per the python style guide.

0👍

First the code to get the project’s path is wrong:

PROJECT_DIR_PATH = path.dirname(path.dirname(__file__))

You need to get an absolute path and calling dirname twice on __file__ does not make sense:

PROJECT_DIR_PATH = path.dirname(path.normpath(path.abspath(__file__)))

Second you also need to fix MEDIA_URL like

MEDIA_URL = "/images/"

Leave a comment