Dnia 05-08-2010 o 14:57:04 Reinout van Rees <rein...@vanrees.org> napisaƂ(a):

On 08/05/2010 01:36 PM, bagheera wrote:
Hi, i set up static files for development purposes in following way:

urls.py:


if settings.DEBUG:
urlpatterns += patterns('',(r'^site_media/(?P<path>.*)$',
'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),)

settings.py:

MEDIA_ROOT = '/home/bagheera/NetBeansProjects/nml-src/storage'
MEDIA_URL = 'http://localhost:8000/site_media/'

index.html template:

<img alt="dupa" src="{{ MEDIA_URL }}site_media/images/clock.gif"</img>

WHY i had to add "site_media" string, when it IS already included in
MEDIA_URL ?
If i use
<img alt="dupa" src="{{ MEDIA_URL }}images/clock.gif"</img>
dev server gives output:
/images/clock.gif/ HTTP/1.1" 404 2155

Full path to this file is:
'/home/bagheera/NetBeansProjects/nml-src/storage/images/clock.gif'

Probably MEDIA_URL isn't set at all in that template. If even the "localhost:8000" isn't showing up...

I saw that problem once, too. The reason was that the template is rendered without the proper context. You'll need to pass along a RequestContext:


from django.template import RequestContext

def your_view(request):
     ...
     return render_to_response(
         your_template,
         {'some': 'parameter'},
         context_instance=RequestContext(request))


Reinout


context_instance=RequestContext(request) solves the problem, i had also fall back to <img alt="dupa" src="{{ MEDIA_URL }}images/clock.gif"</img>, witch now is working fine. Thanks


--
Linux user

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to