The full text of the error is:
错误的全文是:
TemplateSyntaxError at /
在/的TemplateSyntaxError
Caught an exception while rendering: current transaction is aborted, commands ignored until end of transaction block
渲染时捕获异常:当前事务被中止,命令被忽略直到事务块结束
I've recently reinstalled all the software on my computer. The code used to work no problem before. It also still works no problem on a friend's computer and on a development server.
我最近重新安装了计算机上的所有软件。之前使用的代码没问题。它在朋友的计算机和开发服务器上仍然没有问题。
The only thing I can think of, which may have changed is the postgresql server version (and I'm not actually certain whether I tried running it on 8.4 on my old installation or not - it definitely worked on 8.3). Is anyone able to confirm that Django has problems with postgresql 8.4 and/or has any hints as to why I'm having these errors?
我唯一能想到的,可能已经改变的是postgresql服务器版本(我实际上并不确定我是否尝试在旧版安装上运行它,或者不是 - 它绝对适用于8.3)。有人能够确认Django有postgresql 8.4的问题和/或有任何提示,为什么我有这些错误?
Edit 1
In response to Dominic... This doesn't happen just on one page or with one tag (though there are some pages which seem to be ok). The only thing the tags and variables that cause errors have in common is that they happen to access the database somewhere along the way (though not all tags that access the database cause the error). Furthermore, the same code does not create TemplateSyntaxError on other computers.
回应Dominic ......这不仅仅发生在一个页面或一个标签上(虽然有些页面似乎没问题)。导致错误的标记和变量的唯一共同点是它们碰巧在某个地方访问数据库(尽管并非所有访问数据库的标记都会导致错误)。此外,相同的代码不会在其他计算机上创建TemplateSyntaxError。
If I remove a variable or custom template tag that is making the error then this is the chain of events that happens:
如果我删除了发生错误的变量或自定义模板标记,那么这就是发生的事件链:
- I remove the variable or tag that is supposedely causing the error and refresh the page.
- 我删除了导致错误并刷新页面的变量或标记。
- Django picks a different variable or tag and the same error occurs, so I keep removing them.
- Django选择一个不同的变量或标签,并发生相同的错误,所以我一直删除它们。
- Once all the variables and tags that cause the error are removed, I stop getting a proper error page. I get a plain white page with the following traceback:
- 一旦导致错误的所有变量和标签被删除,我就会停止获得正确的错误页面。我得到一个纯白页,其中包含以下回溯:
Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 279, in run self.result = application(self.environ, self.start_response) File "/usr/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 651, in __call__ return self.application(environ, start_response) File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 245, in __call__ response = middleware_method(request, response) File "/usr/lib/python2.6/site-packages/debug_toolbar/middleware.py", line 90, in process_response response.content = replace_insensitive(smart_unicode(response.content), u'', smart_unicode(self.debug_toolbars[request].render_toolbar() + u'')) File "/usr/lib/python2.6/site-packages/debug_toolbar/toolbar/loader.py", line 72, in render_toolbar 'BASE_URL': self.request.META.get('SCRIPT_NAME', ''), File "/usr/lib/python2.6/site-packages/django/template/loader.py", line 108, in render_to_string return t.render(context_instance) File "/usr/lib/python2.6/site-packages/django/test/utils.py", line 29, in instrumented_test_render return self.nodelist.render(context) File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 779, in render bits.append(self.render_node(node, context)) File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 71, in render_node result = node.render(context) File "/usr/lib/python2.6/site-packages/django/template/defaulttags.py", line 155, in render nodelist.append(node.render(context)) File "/usr/lib/python2.6/site-packages/django/template/defaulttags.py", line 243, in render return self.nodelist_true.render(context) File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 779, in render bits.append(self.render_node(node, context)) File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 81, in render_node raise wrapped TemplateSyntaxError: Caught an exception while rendering: current transaction is aborted, commands ignored until end of transaction block Original Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 71, in render_node result = node.render(context) File "/usr/lib/python2.6/site-packages/django/template/debug.py", line 87, in render output = force_unicode(self.filter_expression.resolve(context)) File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 546, in resolve obj = self.var.resolve(context) File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 687, in resolve value = self._resolve_lookup(context) File "/usr/lib/python2.6/site-packages/django/template/__init__.py", line 722, in _resolve_lookup current = current() File "/usr/lib/python2.6/site-packages/debug_toolbar/panels/template.py", line 64, in content pformat(k(self.request))) for k in get_standard_processors() File "/usr/lib/python2.6/site-packages/django/core/context_processors.py", line 27, in auth 'messages': user.get_and_delete_messages(), File "/usr/lib/python2.6/site-packages/django/contrib/auth/models.py", line 263, in get_and_delete_messages for m in self.message_set.all(): File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 106, in _result_iter self._fill_cache() File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 692, in _fill_cache self._result_cache.append(self._iter.next()) File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 238, in iterator for row in self.query.results_iter(): File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py", line 287, in results_iter for rows in self.execute_sql(MULTI): File "/usr/lib/python2.6/site-packages/django/db/models/sql/query.py", line 2369, in execute_sql cursor.execute(sql, params) File "/usr/lib/python2.6/site-packages/debug_toolbar/panels/sql.py", line 91, in execute return self.cursor.execute(sql, params) InternalError: current transaction is aborted, commands ignored until end of transaction block
2 个解决方案
#1
13
That exception means that there was an error in some SQL that is getting executed. Since Django runs all the SQL inside of a database transaction, all the SQL that is being executed after the error gets ignored. So:
该异常意味着某些SQL中的错误正在执行。由于Django在数据库事务中运行所有SQL,因此忽略错误后正在执行的所有SQL。所以:
BEGIN;
SELECT * FROM table;
SELECT missing_column FROM table WHERE id = 1; -- generates an error because the column is missing
SELECT * FROM another_table; -- this statement and all following statements get ignored until the next COMMIT;
COMMIT;
To figure out the problem, find your log file for PostgreSQL and run tail -f /path/to/postgresql_error.log
. Then refresh the page. You should see the error come up in the log file.
要弄清楚问题,找到PostgreSQL的日志文件并运行tail -f /path/to/postgresql_error.log。然后刷新页面。您应该会在日志文件中看到错误。
#2
4
If you're moving from a different DB, note that there might be some considerations to bear in mind with the way that Django with Postgres uses transactions. Have a read here:
如果您从不同的数据库迁移,请注意Django与Postgres使用事务的方式可能需要考虑一些因素。在这里阅读:
http://docs.djangoproject.com/en/dev/topics/db/transactions/?from=olddocs#handling-exceptions-within-postgresql-transactions
The quick answer is usually to turn on database level autocommit by adding:
快速回答通常是通过添加以下内容来打开数据库级自动提交:
'OPTIONS': {'autocommit': True,}
to your database settings. But it's worth having a read up on it and understanding the coo.
到您的数据库设置。但值得阅读并理解首席执行官。
Rolo.
罗洛。
#1
13
That exception means that there was an error in some SQL that is getting executed. Since Django runs all the SQL inside of a database transaction, all the SQL that is being executed after the error gets ignored. So:
该异常意味着某些SQL中的错误正在执行。由于Django在数据库事务中运行所有SQL,因此忽略错误后正在执行的所有SQL。所以:
BEGIN;
SELECT * FROM table;
SELECT missing_column FROM table WHERE id = 1; -- generates an error because the column is missing
SELECT * FROM another_table; -- this statement and all following statements get ignored until the next COMMIT;
COMMIT;
To figure out the problem, find your log file for PostgreSQL and run tail -f /path/to/postgresql_error.log
. Then refresh the page. You should see the error come up in the log file.
要弄清楚问题,找到PostgreSQL的日志文件并运行tail -f /path/to/postgresql_error.log。然后刷新页面。您应该会在日志文件中看到错误。
#2
4
If you're moving from a different DB, note that there might be some considerations to bear in mind with the way that Django with Postgres uses transactions. Have a read here:
如果您从不同的数据库迁移,请注意Django与Postgres使用事务的方式可能需要考虑一些因素。在这里阅读:
http://docs.djangoproject.com/en/dev/topics/db/transactions/?from=olddocs#handling-exceptions-within-postgresql-transactions
The quick answer is usually to turn on database level autocommit by adding:
快速回答通常是通过添加以下内容来打开数据库级自动提交:
'OPTIONS': {'autocommit': True,}
to your database settings. But it's worth having a read up on it and understanding the coo.
到您的数据库设置。但值得阅读并理解首席执行官。
Rolo.
罗洛。