python django 创建数据库和自动化admin

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值