xadmin后台管理
安装:luffy虚拟环境下
INSTALLED_APPS = [
'xadmin',
'crispy_forms',
'reversion',
]
xadmin:需要自己的数据库模型类,完成数据库迁移
python manage.py makemigrations
python manage.py migrate
import xadmin
xadmin.autodiscover()
from xadmin.plugins import xversion
xversion.register_models()
urlpatterns = [
path(r'xadmin/', xadmin.site.urls),
]
创建超级用户:外层luffyapi路径终端
python manage.py createsuperuser
完成xadmin全局配置:新建home/adminx.py
import xadmin
from xadmin import views
class GlobalSettings(object):
"""xadmin的全局配置"""
site_title = "站点标题"
site_footer = "XXXXX有限公司"
menu_style = "accordion"
xadmin.site.register(views.CommAdminView, GlobalSettings)
在adminx.py中注册model:home/adminx.px
from . import models
xadmin.site.register(models.Banner)
修改app:home的名字:xadmin页面上的显示效果
default_app_config = "home.apps.HomeConfig"
from django.apps import AppConfig
class HomeConfig(AppConfig):
name = 'home'
verbose_name = '我的首页'