gpt4 book ai didi

python - Django TemplateSyntaxError : current transaction is aborted, 这个异常是什么意思? postgresql 8.4 可以在 django 上正常工作吗?

转载 作者:行者123 更新时间:2023-12-02 07:37:35 29 4
gpt4 key购买 nike

错误的全文是:

TemplateSyntaxError at /

Caught an exception while rendering: current transaction is aborted, commands ignored until end of transaction block

我最近重新安装了计算机上的所有软件。该代码以前运行没有问题。它在 friend 的计算机和开发服务器上仍然可以正常工作。

我能想到的唯一可能发生变化的是 postgresql 服务器版本(而且我实际上不确定我是否尝试在旧安装上的 8.4 上运行它 - 它肯定可以在 8.3 上运行)。有谁能够确认 Django 在 postgresql 8.4 上存在问题和/或有任何提示说明为什么我会遇到这些错误?

编辑 1

回应多米尼克...这种情况不仅仅发生在一页或一个标签上(尽管有些页面似乎没问题)。导致错误的标签和变量唯一的共同点是它们碰巧在途中的某个地方访问数据库(尽管并非所有访问数据库的标签都会导致错误)。此外,相同的代码不会在其他计算机上创建 TemplateSyntaxError。

如果我删除导致错误的变量或自定义模板标记,则会发生以下事件链:

  1. 我删除了可能导致错误的变量或标记并刷新页面。
  2. Django 选择了不同的变量或标签,并且发生了相同的错误,因此我不断删除它们。
  3. 一旦删除了导致错误的所有变量和标签,我就不再获得正确的错误页面。我得到一个带有以下回溯的纯白色页面:
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 wrappedTemplateSyntaxError: Caught an exception while rendering: current transaction is aborted, commands ignored until end of transaction blockOriginal 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

最佳答案

该异常意味着正在执行的某些 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;

要找出问题,请找到 PostgreSQL 的日志文件并运行 tail -f/path/to/postgresql_error.log。然后刷新页面。您应该会在日志文件中看到错误。

关于python - Django TemplateSyntaxError : current transaction is aborted, 这个异常是什么意思? postgresql 8.4 可以在 django 上正常工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1867407/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com