Django项目的问题汇总
一、执行Django问题
File “/home/cdd/Desktop/Django/typeidea-env/lib/python3.8/site-packages/django/db/backends/sqlite3/creation.py”, line 13, in is_in_memory_db
return database_name == ‘:memory:’ or ‘mode=memory’ in database_name
TypeError: argument of type ‘PosixPath’ is not iterable
这个问题应该是django2.0版本和python新版本不兼容导致的
django2.0中,django/db/backends/sqlite3/creation.py的代码如下
1)解决方案:
vim /usr/local/lib64/python3.6/site-packages/django/db/backends/sqlite3/creation.py +12
@staticmethod
def is_in_memory_db(database_name):
return database_name == ':memory:' or 'mode=memory' in database_name
最新的django3.1此处的代码为
vim /usr/local/lib64/python3.6/site-packages/django/db/backends/sqlite3/creation.py +12
@staticmethod
def is_in_memory_db(database_name):
return not isinstance(database_name, Path) and (
database_name == ':memory:' or 'mode=memory' in database_name
)
如果不想升级django的话可以参照新版django修改即可。
不过要在文件前面导入Path,即:
from pathlib import Path
2)解决方案:
# 安装Django 3.0版本
pip3 install django==3.2.1
二、Django部署阿里云服务时候报错:SQLite 3.8.3 or later is required (found 3.7.17)
问题描述:
在阿里云的自带centos上运行python manage.py runserver的时候报错:
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).
解决方法1:给Django降级
卸载django: pip uninstall django
安装低版本:pip install django==2.1.8
解决方法2:升级SQLite
1.查看系统的sqlte3的版本
sqlite3 --version
提示:Centos系统自带的sqlite3版本偏低,在上面的错误提示中要求需要SQLite 3.8.3 or later,那么就需要去升级 SQlite 的版本了
2.Centos7安装最新的sqlite3并设置更新python库版本
# 更新SQLite 3
# 获取源代码(在主目录中运行)
cd /opt/
wget https://www.sqlite.org/2019/sqlite-autoconf-3270200.tar.gz
tar -zxf sqlite-autoconf-3270200.tar.gz
# 构建并安装
cd sqlite-autoconf-3270200
./configure --prefix=/usr/local
make && make install
find /usr/ -name sqlite3
检查版本
/usr/local/bin/sqlite3 --version
3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7
# Centos7自带的sqlite3版本
/usr/bin/sqlite3 --version
3.7.17 2013-05-20 00:56:22 118a3b35693b134d56ebd780123b7fd6f1497668
# 更改旧的sqlite3
mv /usr/bin/sqlite3 /usr/bin/sqlite3_old
# 软链接将新的sqlite3设置到/usr/bin目录下
ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3
将路径传递给共享库
# 设置开机自启动执行,可以将下面的export语句写入 ~/.bashrc 文件中,如果如果你想立即生效,可以执行source 〜/.bashrc 将在每次启动终端时执行
vim ~/.bashrc
export LD_LIBRARY_PATH="/usr/local/lib"
#检查Python的SQLite3版本
[root@web01 DataServer01]# ipython3
Python 3.6.10 (default, May 10 2021, 12:20:09)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.3.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import sqlite3
In [2]: sqlite3.sqlite_version
Out[2]: '3.27.2'
In [3]: exit
启动开发服务器
# 切换 Django项目下 执行manage.py配置
python3 manage.py runserver
三、UWSGI的问题
[root@web01 website]# uwsgi --ini uwsgi.ini
[uWSGI] getting INI configuration from uwsgi.ini
open("./python_plugin.so"): No such file or directory [core/utils.c line 3732]
!!! UNABLE to load uWSGI plugin: ./python_plugin.so: cannot open shared object file: No such file or directory !!!
# 解决:若是使用的uwsgi 的配置文件是 .ini 类型时
注释 # plugin = python
2)unavailable modifier requested: 0
yum install uwsgi-plugin-python -y
四、安装 ipython 配置
地址: