# =====> 后台管理系统 # 1.admin注册 from django.contrib import admin from .models import UserProfile class UserProfileAdmin(admin.ModelAdmin): pass admin.site.register(UserProfile, UserProfileAdmin) # 2.xadmin # --------------> 方式1,命令安装 1.安装xadmin pip install xadmin 2.注册app ‘xadmin‘ ‘crispy_forms‘ # 是安装xadmin时自动安装的依赖包; 3.替换原装admin # urls.py import xadmin ... url(r‘^xadmin/‘, xadmin.site.urls), # 去掉默认的admin注册方式 4.同步xadmin的表 # 迁移 makemigrations, migrate # ---------------> 方式2,源码安装(推荐)体验新功能---------------------------|||||| 1.在github上下载xadmin源码 2.放入项目中extra_apps中 3.在应用下创建adminx.py文件,用于注册models; 4.注册: import xadmin from .models import EmailVerifyRecord class EmailVerifyRecordAdmin(object): # 注意,这里继承的是object; pass xadmin.site.register(EmailVerifyRecord, EmailVerifyRecordAdmin) 5.自行添加admin其他功能; # list_display # search_fields # list_filter # 3.xadmin相关配置 1.xadmin主题修改、 # 将全站的配置放在users这个应用的adminx.py中; class BaseSetting(object): # 显示主题 enable_themes = True use_bootswatch = True # 注册: from xadmin import views xadmin.site.regitser(views.BaseAdminView, BaseSetting) 2.修改xadmin站点名称等文字 class GlobalSettings(object): site_title = "后台管理系统" site_footer = "Mic在线后台" # 左侧菜单栏收缩功能 menu_style = "accordion" # 注册: xadmin.site.register(views.CommAdminView, GlobalSettings) # ------------ >> 以上是全站配置; 3.中文化app名称 ①新建apps.py # 在对应应用中的apps.py文件中修改 from django.apps import AppConfig class NewsConfig(AppConfig): name = ‘news‘ verbose_name = "新闻" ②__init__.py default_app_config = "news.apps.NewsConfig" # ------->> 修改所有应用; =========================================================
时间: 2024-10-13 04:04:08