Make sure that "django.core.context_processors.media" is listed in
TEMPLATE_CONTEXT_PROCESSORS of your settings.py.

If above context processor is not listed then MEDIA_URL won't be
available in template.

Another reason for this can be that you are using render_to_response
instead of render in your view function. render forces the use of
RequestContext but in render_to_response you have to manually  use the
request variable while creating RequestContext.

Please have a look at
http://stackoverflow.com/questions/5154358/django-what-is-the-difference-between-render-render-to-response-and-direc
for more details.

Ref - 
https://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-media

On Sun, Apr 7, 2013 at 1:03 PM, Fatih Tiryakioglu <[email protected]> wrote:
> Thank you very much.
>
> I think the problem is about printing variable. {{ MEDIA_URL }} doesn't
> print anything in the template. For now, I solved the problem by using
> absolute path, /media/... .
>
>
> --
>
>
> On Sunday, April 7, 2013 9:20:16 AM UTC+3, psjinx wrote:
>>
>> On Sat, Apr 6, 2013 at 4:11 PM, Fatih Tiryakioglu <[email protected]>
>> wrote:
>> > MEDIA_ROOT = '/home/mehmet/internet_projeleri/site4ust/site4/media'
>> This is the absolute path to your media directory.
>> > MEDIA_URL = '/media/'
>> This means files/directories at MEDIA_ROOT directory will be
>> accessible at an url starting with /media/. For example,
>> /home/mehmet/internet_projeleri/site4ust/site4/media/hello.jpg can be
>> viewed at /media/hello.jpg
>>
>> > STATIC_ROOT = ' '
>> This should be set to absolute path of your static directory. `python
>> manage.py collectstatic` command collects static files from different
>> apps in this directory.
>> > STATIC_URL = '/unnamed/'
>> As explained above for MEDIA_URL
>>
>> If you want to use an image located at
>> /home/mehmet/internet_projeleri/site4ust/unnamed/60830071673353216.jpg
>> then change
>>
>> MEDIA_ROOT="/home/mehmet/internet_projeleri/site4ust/unnamed"
>> MEDIA_URL="/media/"
>>
>> > <img src="{{ MEDIA_URL }}/60830071673353216.jpg" />
>>
>> Above code will work now.
>>
>> --
>>
>> Sincerely,
>> Pankaj Singh
>> http://about.me/psjinx
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



-- 

Sincerely,
Pankaj Singh
http://about.me/psjinx

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to