Admin后台管理-django

心已入冬 提交于 2020-02-02 12:17:45

Admin后台管理-django

@(python)

激活管理界面

  • 首先将django.contrib.admin加入setting.py的INSTALLED_APPS配置中;
    保证INSTALLED_APPS中包含django.contrib.authdjango.contrib.contenttypesdjango.contrib.sessions
    MIDDLEWARE_CLASSES包含django.middleware.common.CommonMiddlewaredjango.contrib.sessions.middleware.SessionMiddlewaredjango.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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!