Django18初体验
1089 浏览 6 years, 1 month
2.4 后台管理和超级用户
版权声明: 转载请注明出处 http://www.codingsoho.com/Admin & Superuser
Createsuperuser命令可以用来创建超级用户,该命令任意时间都能执行
(trydjango18) D:\virtualdir\trydjango18\src>python manage.py createsuperuser
Username (leave blank to use 'codingsoho'): codingsoho
Email address: navicester@qq.com
Password:
Password (again):
Superuser created successfully.
Admin这个backend application号称django这个皇冠上的宝石。 对于django,admin这个是可选的,所以如果要使用这个功能,我们需要像其他app一样在setting文件里的INSTALLED_APPS配置。 每加入一个app,都要执行syncdb/migrate以确保对应的table已经在database里创建。
启用admin
去掉setting和url中的一些注释语句
setting.py
INSTALLED_APPS = (
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
)
app配置好了之后,还需要再把它配置到URL,这样我们能够访问该app.
系统默认加了这些url,但是注释掉了,把#去掉就可以了。
urls.py
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# 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)),
)