django-oraclepool未找到异常

时间:2014-09-15 07:18:38

标签: python django oracle connection-pooling django-oracle

我需要一个django(和oracle数据库)的会话池。 我找到了https://pypi.python.org/pypi/django-oraclepool。但是我该如何使用呢?

我做了一个pip安装并将以下行添加到了settings.py(我在http://pydoc.net/Python/django-oraclepool/1.2/oraclepool.tests.settings/找到了它)

INSTALLED_APPS = (
    'oraclepool',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'axes',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'axes.middleware.FailedLoginMiddleware'
)

EXTRAS = {'min':4,         # start number of connections
          'max':8,         # max number of connections
          'increment':2,   # increase by this amount when more are needed
          'homogeneous':1, # 1 = single credentials, 0 = multiple credentials
          'threaded':True, # server platform optimisation
          'timeout':10,   # connection timeout, 600 = 10 mins
          'log':0,         # extra logging functionality
          'logpath':'.',    # file system path to log file
          'existing':'Unicode',   # Type modifications if using existing database data
          'session': ["alter session set session_cached_cursors = 8;",
                      "alter session set cursor_sharing = 'SIMILAR'"]
          }
CREDENTIALS = {'USER' : '####',
                   'NAME' : 'xe',
                   'PASSWORD' : '####',
                   'HOST' : '####',
                   'PORT' : '7854',
                   'OPTIONS' : {}
                   }
    DATABASES= { 'oraclepool':{'ENGINE' : 'oraclepool',
                           'EXTRAS' : EXTRAS
                          },
             'oracle':{'ENGINE' : 'django.db.backends.oracle',
                       'EXTRAS' : {'existing':'Unicode'}
                       }
             }
    for db in ['oraclepool','oracle']:
        for key in CREDENTIALS.keys():
            DATABASES[db][key] = CREDENTIALS[key]
    DATABASES['default'] = DATABASES['oraclepool']

但是当我想运行我的django项目时,我收到了这个错误:

ImportError: No module named 'oraclepool'

...

django.core.exceptions.ImproperlyConfigured: 'oraclepool' isn't an available dat
abase backend.
Try using 'django.db.backends.XXX', where XXX is one of:
    'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named 'oraclepool'

我错过了一个步骤或代码行吗?

1 个答案:

答案 0 :(得分:1)

您可以在名称中添加pooled参数。像这样:

 DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.oracle',
        'NAME': '#####/XE:POOLED',
        'USER':'#####',
        'PASSWORD':'#####',
    }