《数据分析-SmartChart》SmartChart低代码平台开发部署教程

本文详细介绍了如何使用Python+Django+Echarts搭建SmartChart低代码开发平台,并提供了从项目创建、模块安装、配置调整、数据库初始化到服务器部署的完整步骤。在服务器部署部分,包括了Python3.7的安装、项目上传、模块安装及后台启动服务的流程,同时解决了sqlite3版本低和InvalidHTTP_HOSTHeader的问题。
摘要由CSDN通过智能技术生成

一、SmartChart低代码平台-可视化开发

1.简单了解python + django + echarts开发

python + django + echarts开发记录

2、SmartChart

SmartChart是一个低代码开发平台,支持积木式的可视化开发,集成Python + django +echarts,为开发人员提供灵活的定制化报表功能,可以将Tableu,PowerBI,Echarts的图形进行融合展示,只需要稍微进行设置。

统一的数据处理调度平台,数据管道;

统一的可视化接口平台,为第三方应用提供powerbi,tableau,echart的嵌入式以及扩展服务;

统一的数据上传平台,实现线下数据的收集需求,提供专业的手工上传数据产品;

统一的数据分享平台与smartchart集成,可作为数据中台,实现业务对数据下载的需求以及为第三方提供获取数据的API接口;

元数据管理平台以及数据治理,让数据的来源更清晰,让数据应用更方便,具备自动化,可视化数据血缘分析;

3、部署项目

3.1 创建django项目

## 在djangoProject项目下,创建名称为smartchart的django项目,用来部署smartchart
PS D:\date\PyCharm\djangoProject> django-admin startproject smartchart
## 查看该目录下是否成功创建smartchart
PS D:\date\PyCharm\djangoProject> ls

如果需要,可以使用如下命令在smartchart下创建一个APP,相当于一个大型项目的分系统,子模块,功能模块等,相互之间比较独立,但是也有联系。所有APP共享项目资源

PS D:\date\PyCharm\djangoProject\smartchart> python manage.py startapp [APPName]

3.2 安装smartchart模块

## 首先使用pip list查看smartchart模块是否已经安装
PS D:\date\PyCharm\djangoProject> pip list
## 如果没有安装,则使用pip install smartchart安装smartchart
PS D:\date\PyCharm\djangoProject> pip install smartchart

3.3 调整配置文件

在这里插入图片描述

3.3.1 setting.py文件
  • 修改INSTALL_APPS部分

    ## 添加smart_chart.echart
    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'smart_chart.echart',
    ]
    
  • 修改MIDDLEWARE部分

    ## 注释掉XFrameOptionsMiddleware部分
    MIDDLEWARE = [
        'django.middleware.security.SecurityMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
    ]
    
  • 修改时区部分,设定为中国时区,支持中文基础平台建设

    ## 将原有的这五行配置改为如下:
    LANGUAGE_CODE = 'zh-hans'
    
    TIME_ZONE = 'Asia/Shanghai'
    
    USE_I18N = True
    
    USE_L10N = True
    
    USE_TZ = False
    
3.3.2 url.py文件
## 引入部分添加:
## from django.conf.urls import include
## from django.views.generic import RedirectView

from django.contrib import admin
from django.urls import path
from django.conf.urls import include
from django.views.generic import RedirectView

## urlpatterns部分添加:
## path('echart/',include('smart_chart.echart.urls')),
## path('',RedirectView.as_view(url='echart/index/')),

urlpatterns = [
    path('admin/', admin.site.urls),
    path('echart/',include('smart_chart.echart.urls')),
    path('',RedirectView.as_view(url='echart/index/')),
]

3.4 初始化DB

PS D:\date\PyCharm\djangoProject\smartchart> python manage.py makemigrations
PS D:\date\PyCharm\djangoProject\smartchart> python manage.py migrate

3.5 建立管理员账号

PS D:\date\PyCharm\djangoProject\smartchart> python manage.py createsuperuser
用户名 (leave blank to use 'edz'): [输入你的smartchart登录用户名]
电子邮件地址: [输入你的邮件地址]
Password: [输入你的smartchart登录密码]
Password (again):
这个密码太常见了。
密码只包含数字。
## 这里会因为输入的密码太常见,以及太简单而提示你
## 如果输入y的话,他就会绕过密码并验证用户
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.
PS D:\date\PyCharm\djangoProject\smartchart> 

3.6 启动服务

PS D:\date\PyCharm\djangoProject\smartchart> python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
April 01, 2022 - 14:15:42
Django version 3.2.12, using settings 'smartchart.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

3.7 数据初始化

http://127.0.0.1:8000/echart/init_db/

  • 输入设定的用户名和密码

在这里插入图片描述

  • 初始化成功

在这里插入图片描述

4、SmartChart平台

点击[同步数据完成,返回主页开发],会进进入主页也就是http://127.0.0.1:8000/echart/index/

在这里插入图片描述

自此,SmartChart低代码平台就搭建完成,具体的平台操作需要参考SmartChart使用说明

Gitee-SmartChart使用说明

二、服务器部署SmartChart低代码平台

1.服务器安装python3.7

1.1 首先检查是否已有python环境

## 这里的python2.7.5是centos系统自带的,有些应用依赖于它,
## 所以可以另外安装python3.7,使两个版本共存
[root@zxy_master ~]# python -V
Python 2.7.5

1.2 检查gcc编译器是否安装

## 这里已经安装有,如果没有的话,请使用yum -y install gcc
[root@zxy_master ~]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

1.3 安装依赖包,根据当前应用需要安装指定依赖包

[root@zxy_master ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

1.4 下载python3.7安装包

## 可以去官网下载tgz安装包上传至服务器
## 也可以使用wget命令下载python3.7的镜像
[root@zxy_master software]# wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
[root@zxy_master software]# ls
Python-3.7.3.tgz

1.5 解压python3.7

## 使用tar命令,解压tgz压缩包,解压到/zxy/apps/目录下
[root@zxy_master software]# tar -zxvf Python-3.7.3.tgz -C /zxy/apps/

1.6 执行配置文件,编译,安装

[root@zxy_master Python-3.7.3]# ./configure
## 默认安装在/usr/local/bin目录下
[root@zxy_master Python-3.7.3]# make && make install
......
Installing collected packages: setuptools, pip
Successfully installed pip-19.0.3 setuptools-40.8.0

1.7 测试Python3

## 安装成功
[root@zxy_master Python-3.7.3]# python3
Python 3.7.3 (default, Apr  1 2022, 14:53:30)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello world')
hello world
>>>

2.上传SmartChart项目

## 使用的moba工具连接服务器,直接将项目打包上传上来
[root@zxy_master Python]# ls
djangoProject.zip

## 解压zip文件
[root@zxy_master Python]# mkdir djangoProject
[root@zxy_master Python]# unzip djangoProject.zip djangoProject
[root@zxy_master djangoProject]# ls
db.sqlite3   djangoProject   smartchart  venv 

3.安装需要的模块

## 安装django模块
[root@zxy_master smartchart]# pip3 install Django
## 安装smartchart模块
[root@zxy_master smartchart]# pip3 install smartchart
## 查看已安装的模块
[root@zxy_master smartchart]# pip3 list
Package            Version
------------------ ---------
asgiref            3.5.0
certifi            2021.10.8
charset-normalizer 2.0.12
Django             3.2.12
idna               3.3
pip                19.0.3
PyMySQL            1.0.2
pytz               2022.1
requests           2.27.1
setuptools         40.8.0
smartchart         5.3.12
smartdb            0.5
sqlparse           0.4.2
typing-extensions  4.1.1
urllib3            1.26.9

4.启动项目

4.1 前台启动

## 云服务器开启8000端口
[root@zxy_master smartchart]# python3 manage.py runserver 0.0.0.0:8000
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
April 01, 2022 - 15:41:42
Django version 3.2.12, using settings 'smartchart.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.

登录地址:http://ip:8000/echart/index/

这里的用户名和密码,还是项目创建的时候设置的
在这里插入图片描述

在这里插入图片描述

4.2 后台启动

前台启动的弊端就是,启动项目的同时,这个启动页要一致的保持开启状态

4.2.1 启动脚本
## 在smartchart项目目录下
## 使用nohup命令后台启动python3 manage.py runserver 0.0.0.0:8000
[root@zxy_master smartchart]# vim start.sh
nohup python3 manage.py runserver 0.0.0.0:8000 > out.log 2>&1 &

## 执行脚本
[root@zxy_master smartchart]# sh start.sh

## 可以使用这个命令查看已经后台启动成功
[root@zxy_master smartchart]# ps -ef | grep python3
root       419 27382  0 16:10 pts/0    00:00:00 grep --color=auto python3
root     30552     1  0 16:06 pts/1    00:00:00 python3 manage.py runserver 0.0.0.0:8000
root     30560 30552  0 16:06 pts/1    00:00:02 /usr/local/bin/python3 manage.py runserver 0.0.0.0:8000

4.2.2 关闭脚本
## 在smartchart项目目录下
## 查找到python3启动的进程,并强制关闭
[root@zxy_master smartchart]# vim stop.sh
ps -aux | grep python3|xargs kill -9
## 执行脚本
[root@zxy_master smartchart]# sh stop.sh

## 可以使用这个命令查看已经后台关闭成功
[root@zxy_master smartchart]# ps -ef | grep python3
root       419 27382  0 16:10 pts/0    00:00:00 grep --color=auto python3

5.报错解决

5.1 sqlite3版本低

[root@zxy_master smartchart]# python3 manage.py runserver 0.0.0.0:8000

django.core.exceptions.ImproperlyConfigured: SQLite 3.9.0 or later is required (found 3.7.17).

[root@zxy_master smartchart]# sqlite3 -version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668

5.1.1 安装符合版本
## 下载sqlite
[root@zxy_master software]# wget https://www.sqlite.org/2021/sqlite-autoconf-3350500.tar.gz
## 解压到指定目录
[root@zxy_master software]# tar -zxvf sqlite-autoconf-3350500.tar.gz -C /zxy/apps/
[root@zxy_master software]# cd ../apps/sqlite-autoconf-3350500/
## 执行,编译,安装
[root@zxy_master sqlite-autoconf-3350500]# ./configure --prefix=/usr/local/
[root@zxy_master sqlite-autoconf-3350500]# make && make install
## 将原有sqlite文件重命名
[root@zxy_master sqlite-autoconf-3350500]# mv /usr/bin/sqlite3 /usr/bin/sqlite3.bak
## 将新安装sqlite文件在/usr/bin目录下建立软连接
[root@zxy_master sqlite-autoconf-3350500]# ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3
## 配置环境变量并生效
[root@zxy_master sqlite-autoconf-3350500]# echo export LD_LIBRARY_PATH="/usr/local/lib" >> ~/.bashrc
[root@zxy_master sqlite-autoconf-3350500]# source ~/.bashrc
## 检查版本,高版本sqlite已经安装好
[root@zxy_master sqlite-autoconf-3350500]# sqlite3 -version
3.35.5 2021-04-19 18:32:05 1b256d97b553a9611efca188a3d995a2fff712759044ba480f9a0c9e98fae886
[root@zxy_master sqlite-autoconf-3350500]#

5.2 Invalid HTTP_HOST header

DisallowedHost at /echart/index

Invalid HTTP_HOST header: 'master.spunsugar.top:8000'. You may need to add 'master.spunsugar.top' to ALLOWED_HOSTS.

Request Method: 	GET
Request URL: 	http://master.spunsugar.top:8000/echart/index
Django Version: 	3.2.12
Exception Type: 	DisallowedHost
Exception Value: 	

Invalid HTTP_HOST header: 'master.spunsugar.top:8000'. You may need to add 'master.spunsugar.top' to ALLOWED_HOSTS.
5.2.1 修改配置文件
## 找到smartchart的setting.py文件
## 提示一下这里的[master.spunsugar.top]是域名,当然你也可以使用自己IP地址
## 将ALLOWED_HOSTS = [] 改为 ALLOWED_HOSTS=['master.spunsugar.top']
## 或者可以直接改为ALLOWED_HOSTS=['*']
ALLOWED_HOSTS = ['master.spunsugar.top']

6.项目文件提供

CSDN项目文件资源

下载后,只需上传至服务器
按照以上方式部署即可
djangoproject是主项目名
smartchart是smartchart项目的目录,主要在此
配置完成后
登录名:smartchart
密码:12345678
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DATA数据猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值