Django Simple UI


一、Simple UI 简介

以 Django Admin 为基础,配合Element-UI和Vue,让页面更具现代化。享受 Vue +Element-UI 的开发体验,在项目中使用 Vue 组件,带来高效开发。
官网 https://simpleui.88cto.com/simpleui

二、Simple UI 安装

文档 https://simpleui.72wo.com/docs/simpleui/quick.html#目录

2.1 安装

# pip安装
pip install django-simpleui -i https://pypi.tuna.tsinghua.edu.cn/simple
# 克隆源码本地安装
git clone https://github.com/newpanjing/simpleui
cd simpleui
python setup.py sdist install

2.2 配置

settings.py文件中加入一行simpleui

  # Application definition

  INSTALLED_APPS = [
      'simpleui',
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      ...
  ]

2.3 切换主题

SIMPLEUI_DEFAULT_THEME = 'layui.css'

2.4 图标

simpleui仅为系统默认模块提供了图标,如果要为其他模块指定图标,可以自定义配置 .优先级: 自定义->系统配图->默认图标
图标:https://element.eleme.cn/#/zh-CN/component/icon

SIMPLEUI_ICON = {
    '交换机': 'el-icon-mobile',
    '交换机端口': 'el-icon-mobile',
    '组网设备': 'el-icon-mobile',
    '组网设备端口': 'el-icon-mobile',
}

2.5 自定义菜单

SIMPLEUI_CONFIG = {
    'system_keep': True,
    # 'menu_display': ['Simpleui', '测试', '权限认证', '动态菜单测试'],      # 开启排序和过滤功能, 不填此字段为默认排序和全部显示, 空列表[] 为全部不显示.
    'dynamic': True,  # 设置是否开启动态菜单, 默认为False. 如果开启, 则会在每次用户登陆时动态展示菜单内容
    'menus': [{
        'app': 'auth',
        'name': '权限认证',
        'icon': 'fas fa-user-shield',
        'models': [{
            'name': '用户',
            'icon': 'fa fa-user',
            'url': 'auth/user/'
        }]
    }, {
        'name': '测试',
        'icon': 'fa fa-file',
        'models': [{
            'name': 'Baidu',
            'url': 'http://baidu.com',
            'icon': 'far fa-surprise'
        }, {
            'name': '界面测试1',
            'url': '/test/index',
            'icon': 'fab fa-github'
        },
            {
                'name': '界面测试2',
                'url': '/test/index2',
                'icon': 'fab fa-github'
            }
        ]
    }, {
        'name': '动态菜单测试',
        'icon': 'fa fa-desktop',
        'models': [{
            'name': time.time(),
            'url': 'http://*.*.*.*:8080/zwzx/api/v1/get/pons/custid/?custid=30021880369',
            'icon': 'far fa-surprise'
        }]
    }]
}



STATIC_URL = '/static/'
STATICFILES_DIRS = [(os.path.join(BASE_DIR, 'static'))]
	<head>
		<meta charset="utf-8">
		<title>组网专线.襄阳电信</title>
         <!-- 先引入 jquery -->
{#        <script type="text/javascript" src="{% static 'js/jquery-1.4.4.min.js' %}"></script>#}
        <script src="/static/js/jquery-3.3.1.min.js"></script>
        <script src="/static/js/tableExport.min.js"></script>
{#        <script type="text/javascript" href="{% static 'js/jquery-3.3.1.min.js' %}"></script>#}
{#        <script type="text/javascript" href="{% static 'js/tableExport.min.js' %}"></script>#}

	</head>

在这里插入图片描述

在这里插入图片描述

2.5 重新页面

templates目录中新建admin文件夹 选择继承方式

   {% extends 'admin/login.html' %}

    {% block logo %}
        <div class="logo">
            <img src="data:image//2Q==">
        </div>
    {% endblock %}

    {% block header %}
        <div class="header">专线</div>
    {% endblock %}

2.6 自定义后台的名字、标题

urls.py

admin.site.site_title="名字"
admin.site.site_header="名字"
admin.site.index_title="名字"

# 快速操作
SIMPLEUI_HOME_QUICK = False
# 最近动作
 SIMPLEUI_HOME_ACTION = False
# 或修改home.html

2.7 修改时区,修改系统为中文

LANGUAGE_CODE = ‘zh-hans’

TIME_ZONE = ‘Asia/Shanghai’

USE_I18N = True

USE_L10N = True

USE_TZ = False

2.8 登录页增加验证码功能

pip install django-simple-captcha
pip install django-multi_captcha_admin

setting.py

INSTALLED_APPS = [
    'simpleui',
    'multi_captcha_admin',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',    
]

验证码配置

# 验证码配置
MULTI_CAPTCHA_ADMIN = {
    'engine': 'simple-captcha',
}
# 验证码图片大小
CAPTCHA_IMAGE_SIZE = (78, 35)
# 字符个数
CAPTCHA_LENGTH = 4   
# 超时
CAPTCHA_TIMEOUT = 1  

url.py

from django.contrib import admin
from django.urls import path,include
urlpatterns = [
    path('admin/', admin.site.urls),
    path('captcha/', include('captcha.urls')),
]

login.html

<!-- 在密码显示框下面配置显示验证码 -->
<div class="simpleui-input-inline">
                <el-input prefix-icon="fas fa-lock" type="password" v-model="password" name="password"
                    @keyup.enter.native="login()" placeholder="{% trans 'password' %}" show-password></el-input>
</div>
<div>
                {{ form.captcha }}
</div>

修改样式配置

<style type="text/css">
        #id_captcha_1{
            position: absolute;
            margin:0 0 0 9px; /*上右下左*/
            width: 265px;
            font-size: inherit;
            -webkit-appearance: none;
            border-radius: 4px;
            border: 1px solid #DCDFE6;
            box-sizing: border-box;
            display: inline-block;
            height: 40px;
            line-height: 40px;
            outline: 0;
            padding: 0 15px;
            transition: border-color .2s cubic-bezier(.645,.045,.355,1);
            text-align: center;
        }
    </style>

2.9 使用layui框架

描述](https://img-blog.csdnimg.cn/20210422093258437.png)

STATIC_URL = '/static/'
STATICFILES_DIRS = [(os.path.join(BASE_DIR, 'static'))]
<script src="/static/layui-v2.6.1/layui/layui.js" charset="utf-8"></script> 
# 在template下的hmtl 引用不需要.. 直接/static

2.10 静态文件收集到 STATIC_ROOT

python manage.py collectstatic

把静态文件收集到 STATIC_ROOT中

STATICFILES_DIRS = [ 
            os.path.join(BASE_DIR, "static/"),
			]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static_new/")
#其中STATIC_ROOT和STATICFILES_DIRS默认为None,
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Django 中生成可视化大盘,可以使用以下步骤: 1. 安装 Django Simple Dashboard 使用以下命令安装 Django Simple Dashboard: ``` pip install django-simple-dashboard ``` 2. 创建一个 Django 项目 使用以下命令创建一个新的 Django 项目: ``` django-admin startproject mydashboard ``` 3. 创建一个 Django App 使用以下命令创建一个新的 Django App: ``` python manage.py startapp dashboard ``` 4. 在 settings.py 中添加 Simple Dashboard 在项目的 settings.py 文件中添加以下代码: ```python INSTALLED_APPS = [ # ... 'dashboard', 'simple_dashboard', # ... ] # ... SIMPLE_DASHBOARD = { 'widgets': [ { 'type': 'chartjs.line', 'title': 'My Line Chart', 'data': { 'labels': ['January', 'February', 'March', 'April', 'May', 'June', 'July'], 'datasets': [ { 'label': 'My First dataset', 'backgroundColor': 'rgba(255, 99, 132, 0.2)', 'borderColor': 'rgba(255, 99, 132, 1)', 'borderWidth': 1, 'data': [65, 59, 80, 81, 56, 55, 40] }, { 'label': 'My Second dataset', 'backgroundColor': 'rgba(54, 162, 235, 0.2)', 'borderColor': 'rgba(54, 162, 235, 1)', 'borderWidth': 1, 'data': [28, 48, 40, 19, 86, 27, 90] } ] } } ] } ``` 5. 创建视图函数 在 dashboard/views.py 文件中创建一个视图函数,用于渲染 Simple Dashboard: ```python from django.shortcuts import render from simple_dashboard.views import DashboardView class MyDashboardView(DashboardView): template_name = 'dashboard.html' ``` 6. 创建模板文件 在 dashboard/templates/dashboard.html 文件中添加以下代码: ```html {% extends "simple_dashboard/base.html" %} {% block content %} {{ dashboard }} {% endblock %} ``` 7. 添加 URL 路由 在项目的 urls.py 文件中添加以下代码: ```python from django.urls import path from dashboard.views import MyDashboardView urlpatterns = [ path('dashboard/', MyDashboardView.as_view(), name='dashboard'), ] ``` 8. 运行 Django 项目 使用以下命令运行 Django 项目: ``` python manage.py runserver ``` 现在,您可以在浏览器中访问 http://127.0.0.1:8000/dashboard/,就可以看到生成的可视化大盘了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值