Skip to content

python django

https://mirrors.tuna.tsinghua.edu.cn/help/pypi/ python .\manage.py startapp orgs

sh
通过 django  创建 项目
django-admin startproject  项目名称
django-admin startproject  demo
 创建一个应用
python .\manage.py startapp app
命令行启动
python  .\manage.py  runserver
生成 表结构
python  .\manage.py  makemigrations
python  .\manage.py migrate
django admin 
python  .\manage.py createsuperuser
---------------------------------------
# django部署
www.cnblogs.com/freely/p/8027937.html
先安装  venv  虚拟环境 在虚拟环境中操作
修改settings.py
DEBUG = False
# uwsgi  + nginx 访问django

uwsgi.ini

properties
[uwsgi]
socket = 0.0.0.0:8000

chdir = /root/backendmanage


wsgi-file = /root/backendmanage/backendmanage/wsgi.py


home = /root/backendmanage/.venv


master = true


processes = 4


threads = 2

vacum = true

threads = 2

vacum = true
#使进程在后台运行,并将日志打到指定的日志文件 
daemonize= /root/backendmanage/uwsgi.log 
pidfile=uwsgi.pid

相关命令

sh
# 停止
uwsgi --stop uwsgi.pid
# 启动
uwsgi --ini /root/backendmanage/uwsgi.ini
# 重启
uwsgi  --reload  uwsgi.pid

#  必须关闭 SELINUX=disabled  重启 否则 不生效会有 静态资源403的问题

脚本

sh
#!/bin/bash

case "$1" in
    "start")
         echo "started"
		 uwsgi --ini /root/backendmanage/uwsgi.ini
   ;; 
   "stop")
       echo "stop"
	   uwsgi --stop uwsgi.pid
   ;;
  "restart")
    echo "restart" 
	uwsgi  --reload  uwsgi.pid
	;;
  *) 
    echo "your params is error (start ,stop, restart)"
  ;;
esac