说明:环境是基于windows,如果是linux,请自己修改下
最近想用个开源的文档工具,做一些简单文档处理,扒拉一番,找到了 州的先生 / MrDoc 用起来还不错
代码是基于python的,码云仓库:州的先生 / MrDoc https://gitee.com/zmister/MrDoc
首先在默认的sqlite3下运行很好,体验不错,于是决定用mysql,不过由于是python3.7的平台,出现一些问题,于是自己总结一番。
1、默认的sqlite问题不大,可以直接使用,主要问题出现在配置mysql下
2、因为django对python3的支持存在问题,所以有些需要修正:
./Mrdoc/setting.py 修改如下:
a、因为python3没有mysqldb,改用pymysql,文件加入:
import pymysql
pymysql.install_as_MySQLdb()
b、文件中的database配置如下
DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# 'OPTIONS':{
# 'timeout':20,
# }
# }
'default': {
'ENGINE': 'django.db.backends.mysql', # 使用的数据库后端
'NAME': 'mrdoc', # 数据库名
'USER':'root', # 数据库用户
'PASSWORD':'********', # 数据库用户密码
'HOST':'localhost', # 数据库主机地址
'PORT':'3306', # 数据库端口
}
}
3、 使用过程中,如果提示mysqldb版本错误,是因为使用的pymysql
所以直接去python3目录 ./Lib/site-packages/django/db/backends/mysql/base.py中屏蔽版本检测
#if version < (1, 3, 13):
# raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
4、使用过程中,可能报告encode的错误,这个也是python版本引起的,参考github,
直接修改 ./Lib/site-packages/django/db/backends/mysql/operations.py:
头部引入:
from django.utils.encoding import force_str
修改 last_executed_query()函数如下:
def last_executed_query(self, cursor, sql, params):
# With MySQLdb, cursor objects have an (undocumented) "_executed"
# attribute where the exact query sent to the database is saved.
# See MySQLdb/cursors.py in the source distribution.
return force_str(getattr(cursor, '_executed', None), errors='replace')
至此,MrDoc应该就能在python3+mysql的环境下完美跑起来了。