Admin后台管理-django
@(python)
激活管理界面
- 首先将
django.contrib.admin
加入setting.py的INSTALLED_APPS配置中;
保证INSTALLED_APPS中包含django.contrib.auth
,django.contrib.contenttypes
和django.contrib.sessions
;
MIDDLEWARE_CLASSES包含django.middleware.common.CommonMiddleware
、django.contrib.sessions.middleware.SessionMiddleware
和django.contrib.auth.middleware.AuthenticationMiddleware
。 - 执行
python manage.py migrate
输出是
Operations to perform: Apply all migrations: admin, contenttypes, users, auth, sessions Running migrations: Rendering model states... DONE Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying contenttypes.0002_remove_content_type_name... OK Applying sessions.0001_initial... OK
- 运行
python manage.py createsuperuser
创建管理员账号。
输出是
linaro@cubietruck:~/temp/mysite$ python manage.py createsuperuser Username (leave blank to use 'linaro'): admin Email address: admin@qq.com Password: Password (again): Superuser created successfully. linaro@cubietruck:~/temp/mysite$
- 在浏览器中访问http://ip:8000/admin/访问管理器
修改模型数据
- 使用django自带的web管理界面admin来在页面上修改模型数据。
- 模型注册,需要在admin中注册对应的模型,打开users/admin.py文件,修改如下
from django.contrib import admin from users.models import Info # Register your models here. admin.site.register(Info)
此时刷新管理器页面,可以看见新增的users项
参考文献
http://raytaylorlin.com/Tech/Script/Python/django-note-4/
http://www.pycoding.com/articles/135.html
来源:https://www.cnblogs.com/liton/p/4240055.html