Docs improvement? - MEDIA_URL in templates

2021-01-30 Thread mjnich...@gmail.com
Not sure if this is something worth posting here or not, but I was encouraged to put it up for discussion at least by somebody that knows more than me :) I was recently wanting to display user-uploaded media from a template (an avatar pic in my navbar), and I couldn't really work out the "righ

Re: Docs improvement? - MEDIA_URL in templates

2021-01-30 Thread Tim Graham
Hi Mike, I think you want to use {{ user.avatar.url }}. https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.fields.files.FieldFile.url For future reference, since this is more of a usage question, it would be better to post to django-users. If you want to suggest a documen

Re: Docs improvement? - MEDIA_URL in templates

2021-01-30 Thread Mike Nicholson
Thanks for the suggestion for that specific case. I'll definitely use that! It doesn't, however, address the general case. I have images saved at different URLs that aren't tied to a File field (eg. Resized versions). So the question remains: are the docs clear enough to explain how to do this? O

Re: Docs improvement? - MEDIA_URL in templates

2021-01-30 Thread Tim Graham
I have no problem with your solution, or use MEDIA_URL as described at https://docs.djangoproject.com/en/dev/ref/settings/#media-url. Generally for resized versions I'd use a third-party solution that offers some helpers like https://sorl-thumbnail.readthedocs.io/en/latest/examples.html#templat

Re: Docs improvement? - MEDIA_URL in templates

2021-01-30 Thread Adam Johnson
There's also the media context processor that will inject MEDIA_URL into every template context, which is very similar to how get_media_prefix works: https://docs.djangoproject.com/en/3.1/ref/templates/api/#django-template-context-processors-media On Sat, 30 Jan 2021 at 22:46, Mike Nicholson wrot