xadmin是什麼?Xadmin 採用Python語言編寫,框架層基於最成熟的Web框架 Django,是一個基於Django的admin的一個後臺模板框架。python
# 方式一 pip install xadmin # 方式二 # 下載xadmin源碼包:https://github.com/sshwsfc/xadmin pip install xadmin-master.zip
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'xadmin', 'crispy_forms', ]
# 這裏咱們替換掉admin路由 import xadmin urlpatterns = [ url('xadmin/', xadmin.site.urls), ]
這樣咱們就成功用xadmin替換了admin,能夠看一下頁面對比(上:原始admin)git
# 在app下新建一個adminx.py文件 import xadmin class ModelAdmin(object): pass xadmin.site.register(Model類,ModelAdmin管理類)
這樣咱們就成功將模型類添加至了後臺管理站點,接下來咱們經過一個列子讓你們看到效果:github
其中adminx文件:sql
# -*- coding:utf-8 -*- """ Create by Jim on2019/01/16 """ import xadmin from users.models import People class PeopleAdmin(object): pass xadmin.site.register(People, PeopleAdmin)
接下來咱們經過manage.py@xadmintest控制檯進行數據遷移:django
manage.py@xadmintest > makemigrations "C:\PyCharm 2017.3.7\bin\runnerw.exe" G:\python\python.exe "C:\PyCharm 2017.3.7\helpers\pycharm\django_manage.py" makemigrations "G:/pycharm project/xadmintest" Migrations for 'users': users\migrations\0001_initial.py - Create model People Following files were affected G:\pycharm project\xadmintest\users\migrations\0001_initial.py Process finished with exit code 0 manage.py@xadmintest > migrate "C:\PyCharm 2017.3.7\bin\runnerw.exe" G:\python\python.exe "C:\PyCharm 2017.3.7\helpers\pycharm\django_manage.py" migrate "G:/pycharm project/xadmintest" Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions, users, xadmin Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying contenttypes.0002_remove_content_type_name... 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 auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying sessions.0001_initial... OK Applying users.0001_initial... OK Applying xadmin.0001_initial... OK Applying xadmin.0002_log... OK Applying xadmin.0003_auto_20160715_0100... OK Following files were affected G:\pycharm project\xadmintest\db.sqlite3
而後就是建立管理員帳號了:這裏我設置用戶名爲admin,密碼爲adminjim,郵箱爲空session
manage.py@xadmintest > createsuperuser "C:\PyCharm 2017.3.7\bin\runnerw.exe" G:\python\python.exe "C:\PyCharm 2017.3.7\helpers\pycharm\django_manage.py" createsuperuser "G:/pycharm project/xadmintest" Username (leave blank to use 'administrator'): admin Email address: Warning: Password input may be echoed. Password: adminjim Warning: Password input may be echoed. Password (again): adminjim Superuser created successfully.
登陸帳號:app
這裏咱們發現咱們添加的model就顯示出來了,接下來咱們能夠點擊模型類,而後添加數據框架
添加成功咱們點擊這個數據ssh
這裏咱們能夠修改和刪除,是否是很方便,固然咱們的系統顯示還有不少須要修改,如:主題,左上角的文字,頁面底部文字,列表顯示英文,搜索功能等等,咱們均可以作添加修改,你們回想一下咱們前面在註冊的時候是否是還寫了一個多餘模型管理類呢,那麼他就派上用場了,它就能夠用來操做這些。因爲東西比較多,這裏我就很少說了,期待個人下一篇文章吧。ui