0

嗨,提前感谢您的帮助。我刚刚开始学习 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.
    }
}

再次感谢!

4

2 回答 2

9

你破坏了ENGINE设置。应该是django.db.backends.sqlite3

于 2012-06-19T18:48:47.860 回答
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.                                                                        
    }
}
于 2012-06-19T18:51:14.363 回答