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?
evals to
/media/
, because/media/
is already an absolute path. You want