在django中我尝试使用了最简单的sqlite3
首先设置DATABASES的属性
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': r 'E:\Users\cxz\workspace\pythonST\testByDjango\django\db\test.db', #使用sqlit3要写绝对路径和名称
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
在命令提示行中转到项目下调用manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
You just installed Django's auth system, which means you don't have any superuse
rs defined.
会提示创建用户,输入yes
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
接下来设置admin应用
在installed_apps元组中添加
‘django.contrib.admin’
再这里添加任何东西都需要重新运行一次
manage.py syncdb
显示
Creating tables ...
Creating table django_admin_log
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
在urls.py中引用
from django.contrib import admin
设置
admin.autodiscover()
把 url(r'^admin/', include(admin.site.urls)),前的注释去掉
运行 manage.py runserver
访问http://127.0.0.1:8000/admin/
输入刚才设置的用户名密码即可进入
进入界面的时候是英文,如需改变中文
只需修改settings.py中的
TIME_ZONE = 'Asia/Shanghai'
LANGUAGE_CODE = 'zh-Cn'