本文主要是介绍Django-simpleUI(Django-admin)后台美化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Django-simpleUI
django-amdin控制界面自由定义布局处理(借用图片展示效果)
核心目标是自定义布局控制界面在django-simpleUI中呈现
pingendo工具进行Bootstrap前端开发排版布局
**boostrap免费模板https://sc.chinaz.com/tag_moban/bootstrap.html**
- INSTALLED_APPS 设置
- STATICFILES_DIRS 增加静态配置文件地址
- SIMPLEUI_HOME_PAGE = ‘/pyechart/index/’ 修改首页设置, 指向新创建的控制面板
- SIMPLEUI_CONFIG 自定义simpleui 菜单
- urls 项目URLS配置
urlpatterns = [# 配置admindocurl(r'doc/', include('django.contrib.admindocs.urls'), name='doc'),path(r'', admin.site.urls),#path(r'pyechart/', include('pyechart.urls')),
]
## 第一步 创建项目```python
django-admin startproject demo
第二步 创建APP
python manage.py startapp background
第三步 修改setting.py修改以下几处
ALLOWED_HOSTS = ['*', ]#Application definition
INSTALLED_APPS = ['simpleui','tasks','pyechart','import_export','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','django.contrib.admindocs',# 'demo.apps.DemoConfig',# 注册自己的app'article','demo','finance','rate','mdeditor',
]
#数据库在项目中的settings.py文件中配置
DATABASES = {'default': {'ENGINE': 'django.db.backends.mysql','NAME': 'mysql','USER':'root','PASSWORD':'admin','HOST':'127.0.0.1','PORT':'3306','OPTIONS': {"init_command": "SET foreign_key_checks = 0;",},}
}
(2)增加静态配置文件地址
#增加静态配置文件地址
STATICFILES_DIRS = ['C:/Users/LENOVO/Desktop/simpleui_demo/moban_base/static',os.path.join(BASE_DIR, "blog/static")
]
(3)# 修改首页设置, 指向新创建的控制面板
SIMPLEUI_HOME_PAGE = '/pyechart/index/'
SIMPLEUI_HOME_TITLE = '控制面板'
SIMPLEUI_HOME_ICON = 'fa fa-eye'
(4) 自定义simpleui 菜单
#自定义simpleui 菜单
SIMPLEUI_CONFIG = {# 在自定义菜单的基础上保留系统模块'system_keep': True,# 用于菜单排序和过滤, 不填此字段为默认排序和全部显示。空列表[] 为全部不显示.'menu_display': ['文章管理', '任务管理','综合管理','财务管理','多级菜单测试','测试','认证和授权'],# 设置是否开启动态菜单, 默认为False. 如果开启, 则会在每次用户登陆时刷新展示菜单内容。# 一般建议关闭。'dynamic': False,'menus': [{# 自2021.02.01+ 支持多级菜单,models 为子菜单名,理论上可以无限级'name': '多级菜单测试','icon': 'fa fa-file','models': [{'name': 'Baidu','icon': 'far fa-surprise','models': [{'name': '爱奇艺','url':'/indexs_path'}, {'name': '百度问','url': '/tables_path'},{'name': '图视图','url': '/forms_path'}]}, {'name': 'Google','icon': 'far fa-surprise','models': [{'name': 'Youtube','icon': 'far fa-surprise'}, {'name': 'Gmail','icon': 'far fa-surprise'}, {'name': 'Search','url': 'https://www.baidu.com/'}]}]},{'name': '测试','icon': 'fa fa-file','models': [{'name': 'Baidu','url': 'http://baidu.com','icon': 'far fa-surprise'}, {'name': '内网穿透','url': 'https://www.wezoz.com','icon': 'fab fa-github'}, {'name': '内网穿透','url': 'https://www.wezoz.com','icon': 'fab fa-github'}]}]
}
第四步 项目URLS配置
from django.conf import settings
from django.conf.urls import url
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path,re_path, include
from pyechart.views import IndexViews,tablesViews,formsViews
from blog.views import *admin.site.site_title = '管理后台'
admin.site.site_header = '员工管理后台'urlpatterns = [# 配置admindocurl(r'doc/', include('django.contrib.admindocs.urls'), name='doc'),path(r'', admin.site.urls),path(r'tasks/', include('tasks.urls')),path(r'pyechart/', include('pyechart.urls')),path(r'indexs_path/',IndexViews, name = "charts"),path(r'forms_path/',formsViews,name = "forms"),path(r'tables_path/',tablesViews,name = "tables"),# path(r"blog/",include('blog.urls')),url(r'^blogs/$',get_blogs),url(r'^detail/(\d+)/$',get_details ,name='blog_get_detail'),url(r'mdeditor/', include('mdeditor.urls')),] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)# ===============后台管理路由================
# urlpatterns.extend([
# path('admin/', admin.site.urls),
# ])
第五步 创建static目录
将simpleui静态文件静态文件克隆到根目录
python manage.py collectstatic
第六步 重新迁移同步
python manage.py makemigrations
#从新迁徙django-simpleui 的用户表,即在mysql中常见所需的表
python manage.py migrate
#从新迁徙django-simpleui 的用户表,即在mysql中常见所需的表
python manage.py createsuperuser
#操作(创建超级用户)根据提示创建后台的登录用户
第七步 启动项目
python manage.py runserver 0.0.0.0:9990 #启动django项目
这篇关于Django-simpleUI(Django-admin)后台美化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!