Skip to content

guofuwei/Python-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python-Project

作为 Python 小组大作业的仓库

前端使用指南

1.安装flask框架

pip install flask

2.直接运行python flask_client.py即可

后端使用指南

1.安装运行环境

下面均以ubuntu环境举例

安装 mysql

sudo apt-get update  #更新源
sudo apt-get install mysql-server #安装

安装 redis

sudo apt update
sudo apt install redis-server

安装 python 必要运行包

# 安装虚拟环境
pip install virtualenv`
# 创建虚拟文件夹并进入
virtualenv backend/venv`
# 激活虚拟环境并安装必需包
./backend/venv/bin/activate
pip install -r requirements.txt

2.迁移数据表格

# 记得修改backend/myblog/settings.py 下的mysql数据库设置
cd backend
python manage.py makemigrations
python manage.py migrate

3.启动项目

python manage.py runserver

Docker环境运行

1.安装docker和docker-compose

安装docker

卸载旧版本
sudo apt-get remove docker docker-engine docker.io
添加密钥及Docker软件源
sudo apt-get update && sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
添加国内镜像源
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
添加官方源
# 官方源
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# 官方源
$ echo \
   "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
安装Docker
sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io
启动Docker
sudo systemctl enable docker && sudo systemctl start docker
建立Docker用户组
sudo groupadd docker && sudo usermod -aG docker $USER
配置镜像加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://kzev4hva.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

安装docker-compose

打开以下网站:docker/compose: Define and run multi-container applications with Docker (github.com)

选择合适的版本并下载

重命名为docker-compose并 将其移到/usr/local/bin

2.运行项目

修改前端static/config/config.js文件中的后端地址和后端myblog/settings.py中的mysql和redis地址

在项目根目录下运行docker-compose up -d即可

About

作为Python小组大作业的仓库

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published