[TOC]
基于Tornado的restful API 系统;tornado 建议使用6.0.1
API响应,在任意需要的地方 raise JsonError
from trest.exception import JsonError
raise JsonError('msg')
raise JsonError('msg', 0)
raise JsonError('msg', 1, [])
raise JsonError('msg', 1, [1,2,3])
特别注意: 启动docker环境的时候不需要生产.env文件
git clone https://gitee.com/leeyi/py_admin.git py_admin && cd py_admin
// 删除docker
docker rm -f pya_db_master pya_db_slave pya_up_db pya_redis pya_py_admin
docker-compose -f docker-local.yml up
// 后台运行
docker-compose -f docker-local.yml up -d
// Run a command in a running container
docker exec -it pya_py_admin bash
// Fetch the logs of a container
docker logs -f -t pya_py_admin
git clone https://gitee.com/leeyi/py_admin.git py_admin && cd py_admin
pipenv install --skip-lock --pypi-mirror=http://mirrors.cloud.aliyuncs.com/pypi/simple
// or
pipenv install --dev --skip-lock
// 配置本地开发环境变量,然后启动
cp configs/dev.yaml configs/product.yaml
echo '# RUNTIME_ENV is not one of the local, dev, test, or product
# the colon must have Spaces around it
RUNTIME_ENV : product' > .env
// 开启虚拟环境
pipenv shell
// 启动项目
python server.py --port=5080
// 退出pipenv
exit
pipenv install -e git+https://gitee.com/leeyi/trest.git@master#egg=trest
“ .venv 有84M之多”,在生产环境 CentOS7 中要部署多套代码,它都是一样的,多项目共享一个 venv 节省磁盘空间的方法
在第一个项目 pipenv install 命令之后,执行下面命令
mv .venv /root/.local/share/venv_py_admin
ln -s /root/.local/share/venv_py_admin .venv
之后其他项目 clone 下来之后,只要做软连接就行了
参见 datas/sql 目录
show processlist;
set global validate_password_policy=0;
// for mysql8
set global validate_password.policy=0;
create database db_py_admin default charset utf8 COLLATE utf8_general_ci;
CREATE USER user_py_admin IDENTIFIED BY 'eb27acWq#16E1';
GRANT ALL ON db_py_admin.* TO 'user_py_admin'@'%';
flush privileges;
// 只导出表结构
mysqldump --opt -d db_py_admin -u root -p > datas/db.sql
// alter database db_py_admin collate utf8_general_ci
详细说明在TRest项目的软件架构说明
git clone ...
cd py_admin
tree -I '*svn|*node_module*|*git|py3|*.pyc|__pycache__|statics'
// 生成 RSA 私钥
openssl genrsa -out dev_privkey.pem 1024
// 从密钥中提取公钥
openssl rsa -pubout -in dev_privkey.pem -out dev_pubkey.pem
查询数据用 GET 添加/修改数据用 POST 删除数据用 DELETE
还有发放奖励功能需要做 用户上传头像的功能
from applications.core.utils.encrypter import RSAEncrypter
from applications.vsn1.services import ApiVsnService
(code_, msg_, pubkeyser) = ApiVsnService.pubkeyser('1.0.0')
plaintext = 'Ly123456'
ciphertext = RSAEncrypter.encrypt(plaintext, pubkeyser)
print('ciphertext ', ciphertext)
Content type
Image
Digest
Size
408.4 MB
Last updated
over 6 years ago
docker pull leeyi/py_admin:1.0.1