0

I plot a graph and save it as an image in my model. But, the file is not getting retrived at html page. My models.py:

class MyModel(models.Model):
      ... 
      ...
      photo = models.ImageField(upload_to='graphs',blank=True)

settings.py:

MEDIA_ROOT =  os.path.join(BASE_DIR,"media")

MEDIA_URL =  "/media/"

The file is getting stored in the media/graphs directory. {{ MyModel.photo.url }} is printed correctly as /media/graphs/file_name. But when put in an image tag, it is not getting displayed. Why is this happening so?

Aswin Murugesh
  • 10,831
  • 10
  • 40
  • 69

1 Answers1

0
MEDIA_ROOT =  os.path.join(BASE_DIR,"/media/")

evals to /media/, because /media/is already an absolute path. You want

MEDIA_ROOT =  os.path.join(BASE_DIR,"media")
bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118