About Django——Activate the admin site

The Django admin site is not activated by default – it’s an opt-in thing. To activate the admin site for your installation, do these three things:

  • Uncomment "django.contrib.admin" in the INSTALLED_APPS setting.

  • Run python manage.py syncdb. Since you have added a new application to INSTALLED_APPS, the database tables need to be updated.

  • Edit your mysite/urls.py file and uncomment the lines that reference the admin – there are three lines in total to uncomment. This file is a URLconf; we’ll dig into URLconfs in the next tutorial. For now, all you need to know is that it maps URL roots to applications. In the end, you should have a urls.py file that looks like this:

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'^$', '{{ project_name }}.views.home', name='home'),
    # url(r'^{{ project_name }}/', include('{{ project_name }}.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)),
)


Django管理站点在默认情况下是没有被激活的,但是可以选择激活。激活管理站点需要做以下三件事情:

1、在settings文件中的INSTALLED_APPS中取消"django.contrib.admin"这一行的注释

2、在命令行输入python manage.py syncdb同步数据库,原因是在INSTALLED_APPS中添加了一个新的app,admin,所以数据库也是需要更新的。

3、编辑你的mysite/urls.py文件,并且参照admin取消注释,总共有三行需要取消。这个urls.py的文件就是URLconf,我们将在下一个教程中深入讲解URLconfs,现在已经了解到如何将URL映射到app了,最后编辑完成的urls.py看起来如下所示。

注意:一定要取消掉admin.autodiscover()前面的注释,它是自动载入在INSTALLED_APPS中的admin.py模块。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值