本人使用django创建web项目使用的数据库是sqlite3,python版本为2.5.4,django版本为1.4.5
然后我创建了一个project,配置settings.py文件为
DATABASES = {
'default': {
'ENGINE': [color=red]'sqlite3'[/color], # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': './testDj.db3', # 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.
}
}
确不料报出如下错误
error:no module named base
将配置settings.py文件改为
DATABASES = {
'default': {
'ENGINE':[color=red] 'django.db.backends.sqlite3',[/color] # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': './testDj.db3', # 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.
}
}
可以正常运行
然后我创建了一个project,配置settings.py文件为
DATABASES = {
'default': {
'ENGINE': [color=red]'sqlite3'[/color], # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': './testDj.db3', # 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.
}
}
确不料报出如下错误
error:no module named base
将配置settings.py文件改为
DATABASES = {
'default': {
'ENGINE':[color=red] 'django.db.backends.sqlite3',[/color] # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': './testDj.db3', # 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.
}
}
可以正常运行

本文介绍了使用Django框架创建Web项目时配置SQLite3数据库的方法。解决了因配置不当导致的模块未找到错误,并给出了正确的settings.py文件配置示例。
311

被折叠的 条评论
为什么被折叠?



