I am developing a WebApp using Django.I m a newbie, I have this html file which contains image, i did go through this "link", but now i am getting an error as in parsing the Media Url. Could any let me know what is wrong? I have checked the permissions, even they are correct. !!
This is that image which i am including -
<img border="2" src="{{ MEDIA_URL }}samplelogo.jpg" alt="logo here"/>
This is the urls.py -
from django.conf.urls.defaults import patterns, include, url
import settings
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^gharnivas/$', 'gharnivas.views.index'),
url(r'^media/(?P<path>.*)$','django.views.static.serve',{'document_root': settings.MEDIA_ROOT}),
)
This is the settings.py with media url and root :
MEDIA_ROOT = '/home/nagaraj/ghar/templates/media'
MEDIA_URL = 'http://localhost:8000/media/'
ghar is the django project and gharnivas is the app
Update :
Now I have removed the error of TemplateSyntaxError by replacing Media url to '/media/' as suggested by @Torsten below. But still not getting the image !!
Another query , is it correct that i am using MEDIA_ROOT And MEDIA_URL ? Because some place i even see that they have STATIC_URL and STATIC_ROOT !!
{{ MEDIA_URL }}
outputs empty string? Make sure that
1). 'django.core.context_processors.media'
is in TEMPLATE_CONTEXT_PROCESSORS
2). You pass RequestContext
in your template (by passing context_instance=RequestContext(request)
in render_to_response
or by using direct_to_template
instead).
From Django 1.8 'django.core.context_processors.media'
was moved to
'django.template.context_processors.media'