Opened 11 years ago

Closed 11 years ago

#6321 closed (invalid)

Template processor names with no dots cause admin failure

Reported by: holdenweb Owned by: nobody
Component: Core (Management commands) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I set a local TEMPLATE_CONTEXT_PROCESSOR in my settings file as follows


[i.e. I put the hw_context_processor directly into]. Everything worked fine until I tried the /admin/ pages, when I got a traceback:


Request Method: GET
Request URL:
Django Version: 0.97-pre-SVN-6994
Python Version: 2.4.3
Installed Applications:
Installed Middleware:

File "/usr/lib/python2.4/site-packages/django/core/handlers/" in get_response
  82.                 response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/" in _checklogin
  56.             return view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/views/decorators/" in _wrapped_view_func
  39.         response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/admin/views/" in index
  233.     return render_to_response('admin/index.html', {'title': _('Site administration')}, context_instance=template.RequestContext(request))
File "/usr/lib/python2.4/site-packages/django/template/" in __init__
  102.         for processor in get_standard_processors() + processors:
File "/usr/lib/python2.4/site-packages/django/template/" in get_standard_processors
  80.                 raise ImproperlyConfigured('Error importing request processor module %s: "%s"' % (module, e))

Exception Type: ImproperlyConfigured at /admin/
Exception Value: Error importing request processor module hw_context_processo: "No module named hw_context_processo"

The problem appears to be in /usr/lib/python2.4/site-packages/django/template/, where the code in get_standard_processors assumes there will always be at least one dot in the context processor module names. This surmise was confirmed by putting the context processor in a separate module and altering its spec to "lib.hw_context_processor", when the error went away.

The code causing the problem reads:

  73.  processors = []
  74. for path in settings.TEMPLATE_CONTEXT_PROCESSORS:
  75. i = path.rfind('.')
  76. module, attr = path[:i], path[i+1:]
  77. try:
  78. mod = __import__(module, {}, {}, [attr])
  79. except ImportError, e:
  80. raise ImproperlyConfigured('Error importing request processor module %s: "%s"' % (module, e)) ...

Line 76 could be changed to

if i != -1:
    module, attr = "", path
    <current line 76>

but the empty module name then causes problems in a subsequent call of import().

Since I am a Django noob, I am prepared to accept my coding style was far from perfect. So theAappropriate solution might just be to alter the documentation to tell site developers to always put context processors in separate modules, and check explicitly for that in get_standard_processors().

Hope this helps, it's my first Django ticket.

Change History (1)

comment:1 Changed 11 years ago by Steve Holden <steve@…>

Resolution: invalid
Status: newclosed

This ticket was based on a misunderstanding: since context processors must be callables, not modules, their names should clearly require at least one dot.

I've closed this ticket as invalid, which I hope is the correct action: sorry for the noise.

Note: See TracTickets for help on using tickets.
Back to Top