Django

Code

Ticket #8725 (closed: fixed)

Opened 3 months ago

Last modified 3 months ago

TemplateSyntaxError at /admin/ with [8760]

Reported by: kmtracey Assigned to: mtredinnick
Milestone: 1.0 Component: Core framework
Version: SVN Keywords:
Cc: ville@unessa.net, carl@dirtcircle.com Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I get TemplateSyntaxError at /admin/ after updating to current this AM, isolated to being introduced in [8760]; backing up to [8759] makes it go away. Full cut-and-paste info:

Environment:

Request Method: GET
Request URL: http://lbox:8000/admin/
Django Version: 1.0-beta_2-SVN-8760
Python Version: 2.5.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.sites',
 'django.contrib.humanize',
 'xword.crossword']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware')


Template error:
In template /home/kmt/tmp/django/trunk/django/contrib/admin/templates/admin/base.html, error at line 25
   Caught an exception while rendering: 
   15 : <!-- Container -->
   16 : <div id="container">
   17 : 
   18 :     {% if not is_popup %}
   19 :     <!-- Header -->
   20 :     <div id="header">
   21 :         <div id="branding">
   22 :         {% block branding %}{% endblock %}
   23 :         </div>
   24 :         {% if user.is_authenticated and user.is_staff %}
   25 :         <div id="user-tools">{% trans 'Welcome,' %} <strong>{% if user.first_name %}{{ user.first_name|escape }}{% else %}{{ user.username }}{% endif %}</strong>. {% block userlinks %} {% url django-admindocs-docroot as docsroot %} {% if docsroot %}<a href="{{ docsroot }}">{% trans 'Documentation' %}</a> / {% endif %}<a href="{{ root_path }}password_change/">{% trans 'Change password' %}</a> / <a href="{{ root_path }}logout/">{% trans 'Log out' %}</a>{% endblock %}</div>
   26 :         {% endif %}
   27 :         {% block nav-global %}{% endblock %}
   28 :     </div>
   29 :     <!-- END Header -->
   30 :     {% block breadcrumbs %}<div class="breadcrumbs"><a href="/">{% trans 'Home' %}</a>{% if title %} &rsaquo; {{ title|escape }}{% endif %}</div>{% endblock %}
   31 :     {% endif %}
   32 : 
   33 :         {% if messages %}
   34 :         <ul class="messagelist">{% for message in messages %}<li>{{ message|escape }}</li>{% endfor %}</ul>
   35 :         {% endif %}

Traceback:
File "/home/kmt/tmp/django/trunk/django/core/handlers/base.py" in get_response
  86.                 response = callback(request, *callback_args, **callback_kwargs)
File "/home/kmt/tmp/django/trunk/django/contrib/admin/sites.py" in root
  160.             return self.index(request)
File "/home/kmt/tmp/django/trunk/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/home/kmt/tmp/django/trunk/django/contrib/admin/sites.py" in index
  342.             context_instance=template.RequestContext(request)
File "/home/kmt/tmp/django/trunk/django/shortcuts/__init__.py" in render_to_response
  18.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/home/kmt/tmp/django/trunk/django/template/loader.py" in render_to_string
  107.     return t.render(context_instance)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  756.                 bits.append(self.render_node(node, context))
File "/home/kmt/tmp/django/trunk/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/home/kmt/tmp/django/trunk/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  756.                 bits.append(self.render_node(node, context))
File "/home/kmt/tmp/django/trunk/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/home/kmt/tmp/django/trunk/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  176.         return self.nodelist.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  756.                 bits.append(self.render_node(node, context))
File "/home/kmt/tmp/django/trunk/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/home/kmt/tmp/django/trunk/django/template/defaulttags.py" in render
  245.                     return self.nodelist_true.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  756.                 bits.append(self.render_node(node, context))
File "/home/kmt/tmp/django/trunk/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/home/kmt/tmp/django/trunk/django/template/defaulttags.py" in render
  255.             return self.nodelist_true.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  756.                 bits.append(self.render_node(node, context))
File "/home/kmt/tmp/django/trunk/django/template/debug.py" in render_node
  71.             result = node.render(context)
File "/home/kmt/tmp/django/trunk/django/template/loader_tags.py" in render
  24.         result = self.nodelist.render(context)
File "/home/kmt/tmp/django/trunk/django/template/__init__.py" in render
  756.                 bits.append(self.render_node(node, context))
File "/home/kmt/tmp/django/trunk/django/template/debug.py" in render_node
  81.             raise wrapped

Exception Type: TemplateSyntaxError at /admin/
Exception Value: Caught an exception while rendering: 

Original Traceback (most recent call last):
  File "/home/kmt/tmp/django/trunk/django/template/debug.py", line 71, in render_node
    result = node.render(context)
  File "/home/kmt/tmp/django/trunk/django/template/defaulttags.py", line 373, in render
    url = reverse(self.view_name, args=args, kwargs=kwargs)
  File "/home/kmt/tmp/django/trunk/django/core/urlresolvers.py", line 250, in reverse
    *args, **kwargs)))
  File "/home/kmt/tmp/django/trunk/django/core/urlresolvers.py", line 226, in reverse
    possibilities, pattern = self.reverse_dict.get(lookup_view, [(), ()])
  File "/home/kmt/tmp/django/trunk/django/core/urlresolvers.py", line 159, in _get_reverse_dict
    parent = normalize(pattern.regex.pattern)
  File "/home/kmt/tmp/django/trunk/django/utils/regex_helper.py", line 77, in normalize
    ch, escaped = pattern_iter.next()
StopIteration

There's nothing particularly fancy about my admin setup (no over-ridden templates or anything, so far as I recall). My own views work fine, so far as I've checked. If this is not generally recreatable let me know what info would be most helpful to track it down.

Attachments

regex_helper_r8761.diff (0.6 kB) - added by oggy on 08/31/08 09:03:52.
regex_helper_r8761_with_test.diff (1.2 kB) - added by carljm on 08/31/08 12:17:26.
added regression test to patch

Change History

08/31/08 08:02:58 changed by kmtracey

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Just a note, since you can't see the debug page highlighting in the ticket, it the {% url django-admindocs-docroot as docsroot %} on line 25 that is highlighted. I do have admindocs in my INSTALLED_APPS and documentation was working as of yesterday. Removing it from INSTALLED_APPS and its urlpattern ((r'^admin/doc/', include('django.contrib.admindocs.urls')),) from urls.py, though, doesn't appear to change anything, I still get the error on any attempt to access an admin page.

08/31/08 08:44:49 changed by jacob

  • component changed from Uncategorized to Admin interface.
  • stage changed from Unreviewed to Accepted.

08/31/08 09:03:14 changed by oggy

  • component changed from Admin interface to Core framework.

I upgraded to r8760 today and all hell broke loose with reversing my own views. Fixing one line in regex_helper seems to do the trick, and should hopefully fix this one too.

08/31/08 09:03:52 changed by oggy

  • attachment regex_helper_r8761.diff added.

08/31/08 09:05:24 changed by Uninen

  • cc set to ville@unessa.net.

#8726 might be related to this, although the exception is different.

08/31/08 11:06:30 changed by carljm

  • cc changed from ville@unessa.net to ville@unessa.net, carl@dirtcircle.com.

08/31/08 11:27:15 changed by carljm

I can reproduce this problem (in my own views/templates), and the attached patch fixes it for me.

08/31/08 11:43:03 changed by carljm

I've tracked this problem down to the use of an empty regex in a URLConf. This is useful in order to include an application's urls with no prefix; i.e. something like this at the end of a urlpatterns:

url(r'', include('some_app.urls'))

Based on this, I think the attached patch is the correct fix. The first call to next() will raise StopIteration? if the pattern is zero-length, so it needs to be within the try block.

08/31/08 12:15:32 changed by mtredinnick

  • owner changed from nobody to mtredinnick.
  • status changed from new to assigned.

08/31/08 12:17:26 changed by carljm

  • attachment regex_helper_r8761_with_test.diff added.

added regression test to patch

08/31/08 12:25:50 changed by Alex

  • status changed from assigned to closed.
  • resolution set to fixed.

Fixed in r8763.

09/03/08 11:03:12 changed by FlorentV

Hello,

I get the exact same Template Error with 1.0 RC1. Is that normal (fix not in RC1)?

Since it blocked any use of the admin, I hacked the admin/base.html template, removing the whole link to the documentation.

09/03/08 11:37:04 changed by jacob

FlorentV: can you please post your whole error? Make sure to use the "show copy/paste error" button, and paste the error between {{{ and }}} (three braces) so that Trac displays it OK.

09/04/08 14:35:53 changed by FlorentV

jacob: my bad, it was just a problem with a bad urlconf. I had a reference to a view that didn't “exist” since it was in an app I had commented out in INSTALLED_APPS. So basically it was the same problem as in this ticket: http://code.djangoproject.com/ticket/8854

Of course it's not a bug, just a mistake on my part. But it's too bad the error I got was a not-so-helpful template error. If a reference to a non-existing view in urlconf breaks some important feature of the framework, maybe Django should catch this error earlier on and display a specific error?


Add/Change #8725 (TemplateSyntaxError at /admin/ with [8760])




Change Properties
Action