错误是:尝试在Django中设置服务器时没有名为sqlite3.db.base的模块

时间:2012-06-19 18:44:02

标签: python django

您好,感谢您的帮助。我刚刚开始学习Python和Django,并且一直在尝试在djangoproject.com中设置教程。我一直在尝试设置服务器,但不断收到此错误:

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x108826090>>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 23, in get_validation_errors
from django.db import models, connection
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 44, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django.db.sqlite3.db' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named sqlite3.db.base

我试图使用聚光灯找到sqlite3.db.base,但找不到该模块。当我去终端并导入sys并导入sqlite3时,我没有收到任何错误。终端的Sys.path给了我:

['', 
'/Library/Python/2.7/site-packages/pip-1.1-py2.7.egg', 
'/Library/Python/2.7/site- packages/distribute-0.6.27-py2.7.egg',   
'/Library/Python/2.7/site-packages/nose-1.1.2-py2.7.egg', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', 
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', 
'/Library/Python/2.7/site-packages', 
'/Library/Python/2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']

目前我的settings.py设置为:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.sqlite3.db', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',      # Or path to database file if using sqlite3.
        'USER': '',                      # Not used with sqlite3.
        'PASSWORD': '',                  # Not used with sqlite3.
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
    }
}

再次感谢!

2 个答案:

答案 0 :(得分:9)

您修改了ENGINE设置。它应该是django.db.backends.sqlite3

答案 1 :(得分:1)

这不是关于进口的。您在ENGINE设置中输入错误。必须是这样的:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.                                                              
        'NAME': join(CURRENT_DIR, 'db/cms.db'), # Or path to database file if using sqlite3.                                                                              
        'USER': '',                      # Not used with sqlite3.                                                                                                         
        'PASSWORD': '',                  # Not used with sqlite3.                                                                                                         
        'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.                                                                      
        'PORT': '',                      # Set to empty string for default. Not used with sqlite3.                                                                        
    }
}