So, I'm just starting to learn Django, and I'm trying to run one of the sample applications from the book. Now I am stuck in creating DRY URL. In particular, I cannot get the context handler to work. I create my context processor like this:
from django.conf import settings
and I placed this file in my application, in particular mysite / photoogallery / context_processors.py. My settings.py file at the root of my project contains:
TEMPLATE_CONTEXT_PROCESSORS = ('mysite.context_processors',)
When I try to go to ROOT_URL, which I also specified in my settings.py, I get this error:
TypeError at / gallery /
An object
'module' cannot be called
/ gallery / is ROOT_URL of this particular application. I understand that perhpas can mean a name conflict, but I cannot find it. In addition, when I comment on the definition of TEMPLATE_CONTEXT_PROCESSORS from settings.py, the application does load, however, my thumbnails are not displayed (perhaps because my templates do not know about ROOT_URL, right?). Anyone have any ideas on what might be the problem?
EDIT . Here is information about my .py settings in case it is used:
ROOT_URLCONF = 'mysite.urls' ROOT_URL = '/gallery/' LOGIN_URL = ROOT_URL + 'login/' MEDIA_URL = ROOT_URL + 'media/' ADMIN_MEDIA_PREFIX = MEDIA_URL + 'admin/' TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. ) TEMPLATE_CONTEXT_PROCESSORS = ('mysite.photogallery.context_processors',)
EDIT2 . I am going to add some information about my url files. Essentially, I have root urls.py, real_urls.py, which is also in the root, and urls.py, which exists in the application. Basically, root / urls.py hides ROOT_URL from real_urls.py, which then includes my urls.py application.
root / urls.py:
from django.conf.urls.defaults import *
root / real_urls.py:
from django.conf.urls.defaults import * from django.contrib import admin urlpatterns = patterns('', url(r'^admin/(.*)', admin.site.root), url(r'^', include('mysite.photogallery.urls')), )
root / photogallery / urls.py (note that this probably does not cause any problems, but I add it here if someone wants to see it.):
from django.conf.urls.defaults import * from mysite.photogallery.models import Item, Photo urlpatterns = patterns('django.views.generic', url(r'^$', 'simple.direct_to_template', kwargs={'template': 'index.html', 'extra_context': {'item_list': lambda: Item.objects.all()} }, name='index'), url(r'^items/$', 'list_detail.object_list', kwargs={'queryset': Item.objects.all(), 'template_name': 'items_list.html', 'allow_empty': True }, name='item_list'), url(r'^items/(?P<object_id>\d+)/$', 'list_detail.object_detail', kwargs={'queryset': Item.objects.all(), 'template_name': 'items_detail.html' }, name='item_detail' ), url(r'^photos/(?P<object_id>\d+)/$', 'list_detail.object_detail', kwargs={'queryset': Photo.objects.all(), 'template_name': 'photos_detail.html' }, name='photo_detail'),)