Models
新增/更改Models表后需要生成建库脚本
#生成脚本
python manage.py makemigrations index
#写入库
python manage.py migrate
管理员
python manage.py createsuperuser
将models纳入管理范围
在admin.py或models.py中写入:
from .models import Data
admin.site.register(Data)
这数据库名,我明明没加s,他自动给加了个s。怪
部署
1.安装库
pip install django gunicorn gevent
2.在nginx.conf
的http{}
里添加
http{
upstream app_server {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response
#for a TCP configuration
server 127.0.0.1:8000 fail_timeout=0;
}
}
3.在网站配置里添加
location / {
proxy_pass http://app_server;
proxy_set_header Host $host;
}
一键运行
编辑./run.sh
#!/bin/bash
DIR="$(cd "$(dirname "$0")" && pwd)"
echo $DIR
cd $DIR
PROC_NAME=gunicorn
ProcNumber=$(ps -ef | grep -w $PROC_NAME | grep -v grep | wc -l)
if [ $ProcNumber -ge 0 ]; then
kill $(ps -ef | grep 'gunicorn' | grep -v grep | awk '{print $2}')
fi
nohup gunicorn --config=gunicorn.py djangoProject.wsgi &>/dev/null &