在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'