For any image uploaded by the user, I am generating a Thumbnail. The user uploaded image and thumbnail are stored like this.
media_cdn (folder)
-user_name_1 (folder)
-user_name_2 (folder)
--post_1_title_slug (folder)
---300x180 (folder)
----300x180_user_uploaded_image_1.png
---user_uploaded_image_1.png
--post_2_title_slug (folder)
-user_name_3 (folder)
Since I am using ImageField in models, I can easily use {{ appname.image.url }}
in templates, but this will load the image uploaded. I want to load the thumbnail.
I search on stackoverflow and most people are saying to use {{ MEDIA_URL }}
, like here
I am leaning towards {{ MEDIA_URL }}
because, in the future, the website will be generating more images based on the same user uploaded images.
I am using this as of now,
<img src='{{ MEDIA_URL }}/{{user.username}}/{{ upload.slug }}/300x180/300x180_{{ upload.get_filename }}'>
this is giving out this in the page, (from Inspect element)
/user_name/file_slug/300x180/300x180_image_name.png
{{ MEDIA_URL }}
is not giving its correct url.
FYI,
get_filename
is from models.py where I wrote this to get the file name
def get_filename(self):
return(os.path.basename(self.image.name))
how can I make this work?
I am Using Django 1.11.5
, and Pillow 4.2.1