0. 前言

为了修改一下「关于我们」为可后台修改的模式,特别研究了一下后端使用,以下为我在使用的时候遇到的坑和一些注意的地方。注意本文使用/home为基础目录

1. 更新 Python 到 Python3.7

由于QDU将 Python模块django 升级到2.0,使得Python只能升级到3.6以上版本,看了一下Dockerfile,构建的Python版本为Python3.7,就决定使用Python3.7的版本。但我又想让系统自带的Python2.7和Python3.6与Python3.7共存,就用了以下方法。

a.查看 Python 版本

root# python --version 
Python 2.7.15rc1

b.安装 Python3.7 和 pip3

root# sudo apt-get install python3.7 python3-pip

然后修改一下/usr/local/bin/pip3.7
将第一行

#!/usr/bin/python3

修改为

#!/usr/bin/python3.7

c.为了方便使用,建议创建软连接

查看 Python3.7 和 pip3.7 安装路径:

root# which python3.7 
/usr/bin/python3.7
root# which pip3.7
/usr/local/bin/pip3.7

然后创建新的软连接:

#添加 pip3.7 的软链接
root# sudo ln -s /usr/local/bin/pip3.7 /usr/bin/pip3.7

#测试是否安装成功了
root# python3.7 --version
Python 3.7.1
root# pip3.7 --version
pip 19.1 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)

2. 从 GitHub 上克隆代码

root# git clone https://github.com/QingdaoU/OnlineJudgeFE.git
root# git clone https://github.com/QingdaoU/OnlineJudge.git

3. 配置后端

a.安装所需 Python 模块

root# cd /home/OnlineJudge
root# sudo pip install --no-cache-dir -r ./deploy/requirements.txt

如果pip install过慢可使用一下命令,将pip源换至阿里云

root# sudo pip install --no-cache-dir -r ./deploy/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

安装完之后无报错即可。

b. 初始化数据库和后端

修改./init_db.sh文件的第17和18行修改为

python3.7 manage.py migrate
python3.7 manage.py inituser --username root --password rootroot --action create_super_admin

然后执行一下命令

root# sudo chmod +x init_db.sh
root# ./init_db.sh --migrate

一样无报错即可。

c. 运行后端

python3.7 manage.py runserver

4. 运行前端

具体可以参考稳健 Online Judge 开发记录(二)https://www.zklcdc.top/2019/04/14/38.html

注意这一步要为输入以下代码

export TARGET=http://127.0.0.1:8000

出现以下内容之后,访问127.0.0.1:8080即可出现一个真实的OJ,不过没有判题功能

DONE  Compiled successfully in 31165ms
Listening at http://localhost:8080

遇到 “ ModuleNotFoundError: No module named ‘apt_pkg’ ” 的解决办法

root# sudo apt-get remove --purge python-apt
root# sudo apt-get install -f -y python-apt

参考资料

感谢以下大触和前辈

https://aqazzz.coding.me/qduoj-development-record/
https://blog.csdn.net/danerer/article/details/85343909
https://blog.csdn.net/chenghuikai/article/details/55258957
https://blog.csdn.net/u014221090/article/details/82657401