From c0e8b8c8fd1b4164fc5b59b7d345d8c1b2dee40c Mon Sep 17 00:00:00 2001 From: Joe Erickson Date: Thu, 28 Aug 2008 09:04:28 -0400 Subject: [PATCH] Adding context for accessing media root from templates --- lies/context_processors.py | 3 +++ lies/views.py | 3 ++- settings.py | 4 +++- templates/lie_base.html | 16 ++++++++-------- urls.py | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 lies/context_processors.py diff --git a/lies/context_processors.py b/lies/context_processors.py new file mode 100644 index 0000000..094dbc1 --- /dev/null +++ b/lies/context_processors.py @@ -0,0 +1,3 @@ +def media_url(request): + from django.conf import settings + return {'media_url': settings.MEDIA_URL} diff --git a/lies/views.py b/lies/views.py index b45ca9a..e36788d 100644 --- a/lies/views.py +++ b/lies/views.py @@ -1,6 +1,7 @@ from django.shortcuts import render_to_response from django.http import HttpResponseRedirect,HttpResponse from django.core import urlresolvers,serializers +from django.template import RequestContext from lieswetellourselves.lies.models import Lie,Vote from lieswetellourselves.lies.forms import LieForm from lieswetellourselves.lies.json_encode import json_encode @@ -45,4 +46,4 @@ def list_lies(request): if(request.is_ajax()): return HttpResponse(json_encode(object_list)) else: - return render_to_response('lies/lie_list.html', {'object_list':object_list, 'form': LieForm()}) + return render_to_response('lies/lie_list.html', {'object_list':object_list, 'form': LieForm()}, context_instance=RequestContext(request)) diff --git a/settings.py b/settings.py index 3b70e7d..bd8f16a 100644 --- a/settings.py +++ b/settings.py @@ -40,7 +40,7 @@ # URL that handles the media served from MEDIA_ROOT. Make sure to use a # trailing slash if there is a path component (optional in other cases). # Examples: "http://media.lawrence.com", "http://example.com/media/" -MEDIA_URL = '/site-media/' +MEDIA_URL = '/media/' # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a # trailing slash. @@ -74,6 +74,8 @@ '/home/firstclown/Projects/lieswetellourselves/lies/templates/', ) +TEMPLATE_CONTEXT_PROCESSORS = ('lieswetellourselves.lies.context_processors.media_url',) + INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/templates/lie_base.html b/templates/lie_base.html index 648da1d..bca0712 100644 --- a/templates/lie_base.html +++ b/templates/lie_base.html @@ -3,15 +3,15 @@ {% block title %}{% endblock%} - - - + + + - - - - - + + + + +
diff --git a/urls.py b/urls.py index 101acc4..6d9cc65 100644 --- a/urls.py +++ b/urls.py @@ -13,7 +13,7 @@ # Uncomment the next line for to enable the admin: # (r'^admin/(.*)', admin.site.root), - (r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': '/home/firstclown/Projects/lieswetellourselves/media'}), +# (r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': '/home/firstclown/Projects/lieswetellourselves/media'}), (r'', include('lieswetellourselves.lies.urls')), )