导入错误:没有名为transaction的模块

时间:2015-10-13 12:07:59

标签: python django python-2.7

我在django项目中工作,从1.5版本迁移到1.8版本,我有一些问题,这是一个。当我执行python manage.py runserver时,返回我:

/usr/local/lib/python2.7/dist-packages/django/contrib/admin/models.py:28: RemovedInDjango19Warning: Model class django.contrib.admin.models.LogEntry doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
  class LogEntry(models.Model):
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/models.py:28: RemovedInDjango19Warning: Model class django.contrib.admin.models.LogEntry doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
  class LogEntry(models.Model):
Performing system checks...
System check identified no issues (0 silenced).
You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.
octubre 13, 2015 - 08:57:36
Django version 1.8.4, using settings 'spid.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

在简单视图中显示一切正常,但当我尝试在浏览器中打开网址时,我在浏览器中收到此错误:

  

发生服务器错误。请联系管理员。

并在控制台中出现此错误:

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 170, in __call__
    self.load_middleware()
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 50, in load_middleware
    mw_class = import_string(middleware_path)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", line 26, in import_string
    module = import_module(module_path)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named transaction
[13/Oct/2015 09:03:51] "GET /spid/ HTTP/1.1" 500 59
Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 170, in __call__
    self.load_middleware()
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 50, in load_middleware
    mw_class = import_string(middleware_path)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", line 26, in import_string
    module = import_module(module_path)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named transaction
[13/Oct/2015 09:03:51] "GET /favicon.ico HTTP/1.1" 500 59

1 个答案:

答案 0 :(得分:11)

Django 1.6中的transaction middleware was deprecated,并在Django 1.8中删除。从中间件类中删除以下行。

'django.middleware.transaction.TransactionMiddleware', 

您可以使用新功能ATOMIC_REQUESTS

有关详细信息,请查看解释changes to transactions的文档部分。