奇怪的 django 管理错误
我刚刚在新机器上清理了我的项目,当输入 admin 时,我收到以下错误,这表明 forms.py 中存在一些语法错误(我相信 admin 的表单)。有人见过这样的事情吗? :
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)
如果回溯中提到的 forms.py 文件就是我认为的那个文件,那么这就是导致问题的行:
def __init__(self, *args, **kwargs):
self.father = kwargs.pop('parent', None) if kwargs else None
python 2.4 这里有什么问题吗?
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: TemplateSyntaxError 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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,错误在“/usr/lib/python2.4/site-packages/allaccess/rte_site/management/views.py”中,这是您自己安装的包。
它出现的原因是 Django 需要导入所有视图才能反向查找 URL,而导入此视图会出现语法错误。
更新后编辑 是的,三元 if 语法 -
y if x else z
- 仅适用于 Python 2.5 及更高版本。对于较低版本,您需要将其重写为标准if
语句块。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 standardif
statement block.