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 
wrote:

> 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?
>
> On Sat, 30 Jan 2021, 17:16 Tim Graham,  wrote:
>
>> 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 documentation
>> change after some discussion there, you can create a ticket at
>> https://code.djangoproject.com/.
>>
>>
>> On Saturday, January 30, 2021 at 10:56:36 AM UTC-5 mjnich...@gmail.com
>> wrote:
>>
>>> 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 "right"
>>> way of doing this  from the docs. Docs for using static files in templates
>>> are comprehensive - less so for media files from what I can tell.
>>>
>>> A few SO questions, a bit of trial and error, and finding the
>>> https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#get-media-prefix
>>> docs led me to the solution where I have
>>>
>>> 
>>>
>>> in my base template, then
>>>
>>> >>
>>> in my navbar.
>>>
>>> This works nicely, though I still don't really know if it would be
>>> regarded as the "right" way to do it or if I now have a somewhat "hacky"
>>> solution :)
>>>
>>> On the page
>>>
>>> https://docs.djangoproject.com/en/3.1/howto/static-files/
>>>
>>> it talks about deploying static and media files in prod, and gives an
>>> example of  how to use static files in a template, but no example for media
>>> files. It strikes me that it would be handy if this page gave an example of
>>> how to include a media file in a template.
>>>
>>> Hope I'm not wasting people's time here!
>>>
>>> Cheers
>>>
>>> Mike
>>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django developers (Contributions to Django itself)" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-developers/T1d3HBXrol4/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to
>> django-developers+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-developers/d355974a-931f-425e-a0b7-5f08e7c808b6n%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/CAJtk5%2BsgizzDQYZhnJNGStjzkekqvTjqGk4fU8GKj_yt_%3Df9qQ%40mail.gmail.com
> 
> .
>


-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM0dPOpw56Axqy1J6pLD42B8oXGB6ZpmCheiLoCiR54bSQ%40mail.gmail.com.


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#template-examples.
On Saturday, January 30, 2021 at 5:47:00 PM UTC-5 mjnich...@gmail.com wrote:

> 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? 
>
> On Sat, 30 Jan 2021, 17:16 Tim Graham,  wrote:
>
>> 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 documentation 
>> change after some discussion there, you can create a ticket at 
>> https://code.djangoproject.com/.
>>
>>
>> On Saturday, January 30, 2021 at 10:56:36 AM UTC-5 mjnich...@gmail.com 
>> wrote:
>>
>>> 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 "right" 
>>> way of doing this  from the docs. Docs for using static files in templates 
>>> are comprehensive - less so for media files from what I can tell. 
>>>
>>> A few SO questions, a bit of trial and error, and finding the 
>>> https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#get-media-prefix
>>>  
>>> docs led me to the solution where I have
>>>
>>> 
>>>
>>> in my base template, then 
>>>
>>> >>
>>> in my navbar. 
>>>
>>> This works nicely, though I still don't really know if it would be 
>>> regarded as the "right" way to do it or if I now have a somewhat "hacky" 
>>> solution :)
>>>
>>> On the page 
>>>
>>> https://docs.djangoproject.com/en/3.1/howto/static-files/ 
>>>
>>> it talks about deploying static and media files in prod, and gives an 
>>> example of  how to use static files in a template, but no example for media 
>>> files. It strikes me that it would be handy if this page gave an example of 
>>> how to include a media file in a template. 
>>>
>>> Hope I'm not wasting people's time here!
>>>
>>> Cheers
>>>
>>> Mike
>>>
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Django developers (Contributions to Django itself)" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/django-developers/T1d3HBXrol4/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to 
>> django-develop...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-developers/d355974a-931f-425e-a0b7-5f08e7c808b6n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/02ab0e34-6a06-472c-abca-c375018c237an%40googlegroups.com.


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?

On Sat, 30 Jan 2021, 17:16 Tim Graham,  wrote:

> 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 documentation
> change after some discussion there, you can create a ticket at
> https://code.djangoproject.com/.
>
>
> On Saturday, January 30, 2021 at 10:56:36 AM UTC-5 mjnich...@gmail.com
> wrote:
>
>> 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 "right" way of
>> doing this  from the docs. Docs for using static files in templates are
>> comprehensive - less so for media files from what I can tell.
>>
>> A few SO questions, a bit of trial and error, and finding the
>> https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#get-media-prefix
>> docs led me to the solution where I have
>>
>> 
>>
>> in my base template, then
>>
>> >
>> in my navbar.
>>
>> This works nicely, though I still don't really know if it would be
>> regarded as the "right" way to do it or if I now have a somewhat "hacky"
>> solution :)
>>
>> On the page
>>
>> https://docs.djangoproject.com/en/3.1/howto/static-files/
>>
>> it talks about deploying static and media files in prod, and gives an
>> example of  how to use static files in a template, but no example for media
>> files. It strikes me that it would be handy if this page gave an example of
>> how to include a media file in a template.
>>
>> Hope I'm not wasting people's time here!
>>
>> Cheers
>>
>> Mike
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-developers/T1d3HBXrol4/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/d355974a-931f-425e-a0b7-5f08e7c808b6n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAJtk5%2BsgizzDQYZhnJNGStjzkekqvTjqGk4fU8GKj_yt_%3Df9qQ%40mail.gmail.com.


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 documentation 
change after some discussion there, you can create a ticket at 
https://code.djangoproject.com/.


On Saturday, January 30, 2021 at 10:56:36 AM UTC-5 mjnich...@gmail.com 
wrote:

> 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 "right" way of 
> doing this  from the docs. Docs for using static files in templates are 
> comprehensive - less so for media files from what I can tell. 
>
> A few SO questions, a bit of trial and error, and finding the 
> https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#get-media-prefix
>  
> docs led me to the solution where I have
>
> 
>
> in my base template, then 
>
> 
> in my navbar. 
>
> This works nicely, though I still don't really know if it would be 
> regarded as the "right" way to do it or if I now have a somewhat "hacky" 
> solution :)
>
> On the page 
>
> https://docs.djangoproject.com/en/3.1/howto/static-files/ 
>
> it talks about deploying static and media files in prod, and gives an 
> example of  how to use static files in a template, but no example for media 
> files. It strikes me that it would be handy if this page gave an example of 
> how to include a media file in a template. 
>
> Hope I'm not wasting people's time here!
>
> Cheers
>
> Mike
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/d355974a-931f-425e-a0b7-5f08e7c808b6n%40googlegroups.com.


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 "right" way of 
doing this  from the docs. Docs for using static files in templates are 
comprehensive - less so for media files from what I can tell. 

A few SO questions, a bit of trial and error, and finding 
the 
https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#get-media-prefix 
docs led me to the solution where I have



in my base template, then 

https://docs.djangoproject.com/en/3.1/howto/static-files/ 

it talks about deploying static and media files in prod, and gives an 
example of  how to use static files in a template, but no example for media 
files. It strikes me that it would be handy if this page gave an example of 
how to include a media file in a template. 

Hope I'm not wasting people's time here!

Cheers

Mike

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/d74329ab-1781-4769-be1c-5448431acab9n%40googlegroups.com.