Python的web部署到服务器

开发Python程序

已经开发好的例子

https://github.com/jiuyuesanqiu/dingtouhuice.git

购买阿里云服务器

参考:

https://jingyan.baidu.com/article/a17d5285a347128098c8f201.html

系统选择 centos 最新版系统即可

配置阿里云安全组规则

Python的web部署到服务器_第1张图片
增加一个入方向的规则,到时候可以通过这个端口访问服务

远程连接到服务器

在这里插入图片描述

安装 Python

yum install epel-release
yum install python36

安装Gunicorn

python3 -m pip install gunicorn

安装 PIP

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Python3 get-pip.py

安装django

pip install Django

安装 GIT

yum install git

拉取代码到服务器

git clone https://github.com/jiuyuesanqiu/dingtouhuice.git

切换到项目目录

cd dingtouhuice

安装项目依赖

pip install xalpha
pip install pandas

配置setting.py

配置setting.py 的ALLOWED_HOSTS字段

ALLOWED_HOSTS=['19.239.22.11']  这里填你自己的服务器IP地址

运行

python3 manage.py migrate
gunicorn dingTouHuiCheDjango.wsgi -b 0.0.0.0:8989

访问

http://19.239.22.11:8989/calculate/?code=110022&start=2017-05-06&end=2020-05-06&amount=1000&period=M&nsukey=NR3jlatzQW0wGla96dZxdrmd5shD90vAn%2Fcxy299eIsXfzEbOjDaaYfIur5Y7yMYW97Dr0cpsOW5F0DnVH10%2FdRm%2FJVBw8WsVxxDhrdG4yiDRlZNGdlin5No0VbIVjelzq4zsTtc70v6GkbkNUs3TSpy3iENDmxh0gX51WQJjuCapToOjA7P5kyW1mpAusp5dn3deGCThkSZ8N0xHOUtAg%3D%3D

记得替换你的 IP地址

然后会返回如下JSON数据就成功了!

{
    "基金名称": {
        "0": "易方达消费行业股票"
    },
    "基金代码": {
        "0": "110022"
    },
    "当日净值": {
        "0": 3.002
    },
    "单位成本": {
        "0": 2.3057
    },
    "持有份额": {
        "0": 65924.86
    },
    "基金现值": {
        "0": 197906.43
    },
    "基金总申购": {
        "0": 152000
    },
    "历史最大占用": {
        "0": 152000
    },
    "基金持有成本": {
        "0": 152000
    },
    "基金分红与赎回": {
        "0": 0
    },
    "换手率": {
        "0": 0.1668190128
    },
    "基金收益总额": {
        "0": 45906.43
    },
    "投资收益率": {
        "0": 30.2016
    }
}

有问题可以加微信,欢迎交流编程技术

Python的web部署到服务器_第2张图片

你可能感兴趣的:(Python的web部署到服务器)