(一)设置自动admin应用
打开settings.py的INSTALL_APPS中的'django.contrib.auth'下面添加
'django.contrib.auth',
'django.contrib.admin',
再次运行manage.py syncdb,生成django_admin_log
(二)修改ulrs
打开mysite\mysite\urls.py文件,改为
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'mysite.views.home', name='home'),
# url(r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
(三)修改models
打开mysite\blog\models.py,改为
from django.db import models
from django.contrib import admin
class BlogPost(models.Model):
title=models.CharField(max_length=150)
body=models.TextField()
timestamp=models.DateTimeField()
admin.site.register(BlogPost)
(四)运行测试
运行服务器,输入manage runserver
打开IE,输入http://127.0.0.1:8000/admin/
出现登陆界面,输入用户名和密码即可登陆了