Django项目上线-报错汇总
下列报错基本都是Python环境相关
pip install 报错
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
处理方案
# 散出之前编译安装的Python
rm -rf /usr/local/python3.7/
yum install openssl-devel -y
vim Python-3.7.9/Modules/Setup去除图中的5行注释
重新编译即可
cd Python-3.9.7
./configure --prefix=/usr/local/python3
make && make install
参考:debian运行pip报错ssl module in Python is not available - z417 - 博客园 (cnblogs.com)
项目启动报错
1、ModuleNotFondError:No module named '_sqlite3' | 安装sqlite(未使用)
处理方案:
yum -y install sqlite-devel
find / -name _sqlite3.so
cp /usr/lib64/python2.7/lib-dynload/_sqlite3.so /usr/local/python3.7/lib/python3.7/lib-dynload/参考:Python No module named '_sqlite3' 解决方案_no module named sqlite3-CSDN博客
2、ImportError: dynamic module does not define module export function (PyInit sqlite3) | 安装sqlite(可使用)
处理方案:
# 编译安装Python,并启用编译安装好的sqlite3
LD_RUN_PATH=/usr/local/sqlite3/lib ./configure --prefix=/usr/local/python3.7 LDFLAGS="-L/usr/local/sqlite3/lib" CPPFLAGS="-I /usr/local/sqlite3/include"
LD_RUN_PATH=/usr/local/sqlite3/lib make
LD_RUN_PATH=/usr/local/sqlite3/lib sudo make install参考:
3、django.core,exceptions,ImproperlyConfigured: sOLite 3.9.0 or later is reguired (found 3.7.17)
由于sqlite版本太低,更换版本
处理方案:
# 编译安装sqlite(3.36.0版本)
wget http://www.sqlite.org/2021/sqlite-autoconf-3360000.tar.gz
tar -zxvf sqlite-autoconf-3360000.tar.gz
cd sqlite-autoconf-3360000
./configure --prefix=/usr/local/sqlite
make && make install
# 验证版本
$ python3
>>> import sqlite3
>>> sqlite3.sqlite_version参考:django.core.exceptions.ImproperlyConfigured: SQLite 3.9.0 or later is required (found 3.7.17)-CSDN博客
4、mportError: urllib3 v2.0 only supports 0penssL 1.1.1t, currently the1SSmocule iscompiledwith'0penSsl 1.0.2k-fips 26 J22017', See: https://github.com/urllib3/urllib3/issues/2168
更新urllib3版本
处理方案:
pip install urllib3==1.26.15 -i https://pypi.tuna.tsinghua.edu.cn/simple
参考:
5、You have 1 unapplied migration(s). Your project may not work properly until you apply
运行 python manage.py runserver 0.0.0.0:8000
时,报错
处理方案:
$ python manage.py migrate
# 再次运行
$ python manage.py runserver 0.0.0.0:8000参考:解决:You have 18 unapplied migration(s). Your project may not work properly until you apply-CSDN博客
6、Invalid HTTP_HOST header: '192.168.200.11:8080'. You may need to add '192.168.200.11' to ALLOWED_HOSTS.
添加ALLOWED_HOSTS
解决方法:
修改settings.py
ALLOWED_HOSTS = ['192.168.2.157','127.0.0.1']
值为'*',可以使所有的网址都能访问Django项目了,失去了保护的作用,可以用于测试
ALLOWED_HOSTS = ['*']
参考:Django 遇到 Invalid HTTP_HOST header - 慕尘 - 博客园 (cnblogs.com)
7、local variable 'cursor referenced before assignment
现象:登录报错,应该是数据库没连接上。
原因:数据库没有启动
End
非特殊说明,本博所有文章均为博主原创。
如若转载,请注明出处:https://www.qiuyl.com/baocuo/246
共有 2 条评论