Django+Ubuntu20.04+SQLCipher

一、下载sqlcipher

SQLCipher · GitHub

cd sqlcipher
./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" --disable-tcl
make && make install

可能会出现的问题:

问题一:

configure: error: OpenSSL Crypto library not found

解决办法:

①在线下载:

apt-get install libssl-dev

②离线包下载:

http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl-dev_1.1.1f-1ubuntu2.16_amd64.deb

dpkg -i libssl-dev_1.1.1f-1ubuntu2.16_arm64.deb

问题二:

/bin/sh:1:tclsh:not found

解决办法:

①在线下载:

apt-get install libtcl8.6 tcl8.6

②离线下载:

http://archive.ubuntu.com/ubuntu/pool/main/t/tcl8.6/libtcl8.6_8.6.10+dfsg-1_amd64.deb

http://archive.ubuntu.com/ubuntu/pool/main/t/tcl8.6/tcl8.6_8.6.10+dfsg-1_amd64.deb

分别dpkg安装

问题三:

如果有报错类似:
sqlite3.c:16702:3: error: unknown type name ‘sqlite3’

解决办法:
检查当前目录下sqlite3.h是否为空,如果空的文件就删除

二、下载pysqlcipher3源码

pysqlcipher3 · PyPI

cd pysqlcipher3
python3 setup.py install

三、下载django-sqlcipher

https://github.com/benjaoming/django-sqlcipher/

下载分支develop

cd django-sqlcipher
python3 setup.py install

①找到django_sqlcipher-0.1.2-py3.6.egg安装的位置

②解压django_sqlcipher-0.1.2-py3.6.egg

③将sqlcipher文件夹拷贝到 django/db/backends/ 目录下(有则不用拷贝)

说明:django/db/backends/ 目录下是 django可以用到的数据库引擎

④修改sqlcipher/backend/base.py

将 from pysqlcipher import dbapi2 as Database 改为 from pysqlcipher3 import dbapi2 as Database 保存

四、Django配置sqlcipher引擎

①INSTALLED_APPS中注册 'sqlcipher'
 
②配置数据库密码 PRAGMA_KEY = '654321'
 
③DATABASES = {
    'default': {
      'ENGINE': 'django.db.backends.sqlcipher',  # 使用sqlcipher数据库引擎
           'NAME': os.path.join(BASE_DIR,'db.sqlite3'),
    }
}

④将sqlcipher/backend/base.py移出bakend文件

五、运行django项目

可能遇到的问题:

问题一:

ImportError: libsqlcipher.so.0: cannot open shared object file: No such file or directory

解决方法:

①首先需要打开/etc/ld.so.conf文件

vim /etc/ld.so.conf

②然后在文件中中加入一行

/usr/local/lib

③保存之后,运行

/sbin/ldconfig -v

更新配置后,编译时就不会找不到.so

问题二:

ImportError: cannot import name 'RemovedInDjango20Warning' from 'django.utils.deprecation'

解决方法:

修改sqlcipher/base.py中RemovedInDjango20Warning为RemovedInDjango30Warning

问题三:

AttributeError: module 'django.db.backends.utils' has no attribute 'typecast_decimal'

解决办法:

sqlcipher/base.py中增加

backend_utils.typecast_decimal = decimal.Decimal

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值