激活管理界面:
1、给需要管理的数据表模块添加admin配置
方式:
新建一个 admin.py
Code:
from django.contrib import admin
from models import Publisher,Author,Book
admin.site.register(Publisher)
admin.site.register(Author)
admin.site.register(Book)
特别注意:这个admin.py放在app的目录下,而不是project的目录下
2、修改配置信息 在settings.py中
#1.0新增 admin 时遇到
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
)
修改INSTALLED_APPS
#添加模型位置
INSTALLED_APPS = (
#'django.contrib.auth',
#'django.contrib.contenttypes',
#'django.contrib.sessions',
#'django.contrib.sites',
'mysite.books',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
)
3、urls.py 新增红色内容(实际上通过startproject创建的urls.py本来就有这些内容,放开注释即可):
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
(r'^time/$', cur_datetime),
)
关于admin界面的汉化其实很简单,在setting.py里将LANGUAGE_CODE从en-us改为zh-CN