Strange django admin error
I've just fired my project clean on new machine and when entering admin I got the following error, which indicates some syntax error in forms.py ( I believe admin's forms). Anyone seen anything like this before ? :
Environment:
Request Method: GET
Request URL: http://djtest.test.rte.ie/access/admin/ Django Version: 1.1.2
Python Version: 2.4.3
Installed Applications:
['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'tagging', 'rte_utils.filetransfers', 'rte_utils.syncr', 'rte_utils.twitter', 'rte_utils.youtube', 'rte_utils.flickr', 'rte_site', 'rte_site.static_pages', 'rte_site.artifact', 'rte_site.candid', 'rte_site.events', 'rte_site.playforward', 'rte_site.setspy', 'debug_toolbar'] Installed Middleware:
('django.middleware.cache.UpdateCacheMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.common.CommonMiddleware', 'rte_site.middleware.FlatpageFallbackMiddleware', 'django.middleware.cache.FetchFromCacheMiddleware')
Template error:
In template /usr/lib/python2.4/site-packages/django/contrib/admin/templates/admin/base.html, error at line 30
Caught SyntaxError while rendering: invalid syntax (forms.py, line 227) 20 :
21 :
22 :
23 : {% block branding %}{% endblock %}
24 :
25 : {% if user.is_authenticated and user.is_staff %}
26 :
27 : {% trans 'Welcome,' %}
28 : {% filter force_escape %}{% firstof user.first_name user.username %}{% endfilter %}.
29 : {% block userlinks %}
30 : {% url django-admindocs-docroot as docsroot %}
31 : {% if docsroot %}
32 : {% trans 'Documentation' %} /
33 : {% endif %}
34 : {% url admin:password_change as password_change_url %}
35 : {% if password_change_url %}
36 :
37 : {% else %}
38 :
39 : {% endif %}
40 : {% trans 'Change password' %} /
Traceback:
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in get_response
99. response = callback(request, callback_args, **callback_kwargs) File "/usr/lib/python2.4/site-packages/django/contrib/admin/sites.py" in root
480. return self.index(request) File "/usr/lib/python2.4/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
44. response = view_func(request, args, kwargs) File "/usr/lib/python2.4/site-packages/django/contrib/admin/sites.py" in index
377. context_instance=context_instance File "/usr/lib/python2.4/site-packages/django/shortcuts/init.py" in render_to_response
20. return HttpResponse(loader.render_to_string(*args, kwargs), *httpresponse_kwargs) File "/usr/lib/python2.4/site-packages/django/template/loader.py" in render_to_string
108. return t.render(context_instance) File "/usr/lib/python2.4/site-packages/django/template/init.py" in render
165. return self.nodelist.render(context) File "/usr/lib/python2.4/site-packages/django/template/init.py" in render
784. bits.append(self.render_node(node, context)) File "/usr/lib/python2.4/site-packages/django/template/debug.py" in render_node
71. result = node.render(context) File "/usr/lib/python2.4/site-packages/django/template/loader_tags.py" in render
97. return compiled_parent.render(context) File "/usr/lib/python2.4/site-packages/django/template/init.py" in render
165. return self.nodelist.render(context) File "/usr/lib/python2.4/site-packages/django/template/init.py" in render
784. bits.append(self.render_node(node, context)) File "/usr/lib/python2.4/site-packages/django/template/debug.py" in render_node
71. result = node.render(context) File "/usr/lib/python2.4/site-packages/django/template/loader_tags.py" in render
97. return compiled_parent.render(context) File "/usr/lib/python2.4/site-packages/django/template/init.py" in render
165. return self.nodelist.render(context) File "/usr/lib/python2.4/site-packages/django/template/init.py" in render
784. bits.append(self.render_node(node, context)) File "/usr/lib/python2.4/site-packages/django/template/debug.py" in render_node
71. result = node.render(context) File "/usr/lib/python2.4/site-packages/django/template/defaulttags.py" in render
240. return self.nodelist_true.render(context) File "/usr/lib/python2.4/site-packages/django/template/init.py" in render
784. bits.append(self.render_node(node, context)) File "/usr/lib/python2.4/site-packages/django/template/debug.py" in render_node
71. result = node.render(context) File "/usr/lib/python2.4/site-packages/django/template/defaulttags.py" in render
250. return self.nodelist_true.render(context) File "/usr/lib/python2.4/site-packages/django/template/init.py" in render
784. bits.append(self.render_node(node, context)) File "/usr/lib/python2.4/site-packages/django/template/debug.py" in render_node
71. result = node.render(context) File "/usr/lib/python2.4/site-packages/django/template/loader_tags.py" in render
24. result = self.nodelist.render(context) File "/usr/lib/python2.4/site-packages/django/template/init.py" in render
784. bits.append(self.render_node(node, context)) File "/usr/lib/python2.4/site-packages/django/template/debug.py" in render_node
71. result = node.render(context) File "/usr/lib/python2.4/site-packages/django/template/defaulttags.py" in render
367. url = reverse(self.view_name, args=args, kwargs=kwargs, current_app=context.current_app) File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py" in reverse
357. return iri_to_uri(u'%s%s' % (prefix, resolver.reverse(view, File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py" in reverse
279. possibilities = self.reverse_dict.getlist(lookup_view) File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py" in get_reverse_dict
199. self.populate() File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py" in populate
179. for name in pattern.reverse_dict: File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py" in get_reverse_dict
199. self.populate() File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py" in populate
191. lookups.appendlist(pattern.callback, (bits, p_pattern)) File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py" in get_callback
135. self.callback = get_callable(self._callback_str) File "/usr/lib/python2.4/site-packages/django/utils/functional.py" in wrapper
130. result = func(args) File "/usr/lib/python2.4/site-packages/django/core/urlresolvers.py" in get_callable
62. lookup_view = getattr(import_module(mod_name), func_name) File "/usr/lib/python2.4/site-packages/django/utils/importlib.py" in import_module
35. import(name) File "/usr/lib/python2.4/site-packages/allaccess/rte_site/management/views.py" in ?
38. from forms import AdminForm
Exception Type: Templat开发者_StackOverfloweSyntaxError at /admin/
Exception Value: Caught SyntaxError while rendering: invalid syntax (forms.py, line 227)
If the forms.py file mentioned in traceback is the one I think it is, then this is the line causing problems:
def __init__(self, *args, **kwargs):
self.father = kwargs.pop('parent', None) if kwargs else None
anything wrong here for python 2.4 ?
No, the error is in "/usr/lib/python2.4/site-packages/allaccess/rte_site/management/views.py", which is a package you have installed yourself.
The reason it comes up where it does is because Django needs to import all views in order to reverse-lookup URLs, and importing this view gives a syntax error.
Edited after post update Yes, that ternary if syntax - y if x else z
- is only for Python 2.5 and above. For lower versions, you'd need to rewrite it as a standard if
statement block.
精彩评论