Tip

  • 如果修改完代码,但没变化,可以试试保存两次,ctrl+s两下,浏览器刷新两下

  • 如果models写完makemigrations 显示没变化,看看settings里有没有注册该应用

  • 安全组就是防火墙

  • 连接数据库失败可以删掉数据库重新建一个试试

  • 除了阿里云的安全组、腾讯云的防火墙要开放端口(新建一个),在宝塔面板的安全里也要开放,不然无法访问,页面无法访问一定要检查!!!

  • python manage.py runserver要在venv环境中运行,不然可能因为服务器没下载python不能执行python命令

1
2
3
4
ubuntu@vM-16-13-ubuntu:~$ python manage.py runserver
Command 'python' not found, did you mean:
command 'python3' from deb python3
command 'python' from deb python-is-python3
  • Linux使用source venv/bin/activate进入虚拟环境

  • 下东西也要在虚拟环境里下,不然命令可能运行不了,下错地方需要卸载,在虚拟环境中重新装

1
2
3
4
5
6
7
ubuntu@vM-16-13-ubuntu:/www/wwwroot/websites which gunicorn
/home/ubuntu/.local/bin/gunicorn
ubuntu@vM-16-13-ubuntu:/www/wwwroot/websites sudo /home/ubuntu/.local/bin/gunicorn config.wsgi -c gunicorn_conf.py
Traceback (most recent call last):
File "/home/ubuntu/.local/bin/gunicorn", line 5, in <module>
from gunicorn.app.wsgiapp import run
ModuleNotFoundError: gunicorn
  • 如果运行程序时,没反应,没报错,只有光标一直在闪烁,是运行成功了,所以进程不会结束
1
2
3
4
5
6
(venv)ubuntu@vM-16-13-ubuntu:/www/wwwroot/websites which gunicorn
/www/wwwroot/website/venv/bin/gunicorn
(venv)ubuntu@vM-16-13-ubuntu:/www/wwwroot/websites sudo /www/wwwroot/website/venv/bin/gunicorn config.wsgi -c gunicorn_conf.py
^C(venv) ubuntu@vM-16-13-ubuntu:/www/wwwroot/websites sudo /www/wwwroot/website/venv/bin/gunicorn config.wsgi -c gunicorn_conf.py
<QuerySet>
|
  • 使用netstat -tunlp来看端口是否被监听,被nginx监听到了,就可以访问端口号看到静态资源,如果访问不了,重启nginx然后要等一会,不然刷新会立马显示无法访问
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(venv) root@vM-16-13-ubuntu:/www/wwwroot/movie/dx_movie# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:9100 0.0.0.0:* LISTEN 1283518/nginx: master
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 1283518/nginx: master
tcp 0 0 0.0.0.0:888 0.0.0.0:* LISTEN 1283518/nginx: master
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 148317/sendmail: MTA
tcp 0 0 127.0.0.1:587 0.0.0.0:* LISTEN 148317/sendmail: MTA
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 841/sshd: /usr/sbin/sshd
tcp 0 0 0.0.0.0:41995 0.0.0.0:* LISTEN 582916/python3
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1283518/nginx: master
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 722/systemd-resolved
tcp6 0 0 :::33060 :::* LISTEN 237017/mysqld
tcp6 0 0 :::3306 :::* LISTEN 237017/mysqld
tcp6 0 0 :::22 :::* LISTEN 841/sshd: /usr/sbin/sshd
udp 0 0 127.0.0.53:53 0.0.0.0:* 722/systemd-resolved
udp 0 0 10.0.16.13:68 0.0.0.0:* 720/systemd-networkd
udp 0 0 10.0.16.13:123 0.0.0.0:* 7774/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 7774/ntpd
udp6 0 0 fe80::5054:ff:fee6:123 :::* 7774/ntpd
udp6 0 0 ::1:123 :::* 7774/ntpd