我刚刚在新机器上解决了我的项目问题,当我输入admin时出现以下错误,这表明forms.py中存在一些语法错误(我相信管理员的表单)。以前见过这样的人吗? :
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: TemplateSyntaxError at /admin/
Exception Value: Caught SyntaxError while rendering: invalid syntax (forms.py, line 227)
如果traceback中提到的forms.py文件是我认为的那个,那么这就是引起问题的行:
def __init__(self, *args, **kwargs):
self.father = kwargs.pop('parent', None) if kwargs else None
python 2.4有什么问题吗?
答案 0 :(得分:1)
不,错误位于“/usr/lib/python2.4/site-packages/allaccess/rte_site/management/views.py”,这是您自己安装的软件包。
它出现的原因是因为Django需要导入所有视图才能反向查找URL,导入此视图会产生语法错误。
在更新后编辑是的,那个三元语法 - y if x else z
- 仅适用于Python 2.5及更高版本。对于较低版本,您需要将其重写为标准if
语句块。