如何使 Django 与不受支持的 MySQL 驱动程序(例如 gevent-mysql 或 Concurrence 的 MySQL 驱动程序)一起工作?
我有兴趣在 Concurrence 或 gevent 等异步框架上运行 Django。这两个框架都带有自己的异步 MySQL 驱动程序。
问题是 Django 仅官方支持 MySQLdb。我需要做什么才能使 Django 与 gevent 或 Concurrence 附带的 MySQL 驱动程序一起工作?
有我可以遵循的分步指南吗?这是一项重大事业吗?
谢谢。
I'm interested in running Django on an async framework like Concurrence or gevent. Both frameworks come with its own async MySQL driver.
Problem is Django only officially supports MySQLdb. What do I need to do to make Django work with the MySQL drivers that come with gevent or Concurrence?
Is there a step-by-step guide somewhere that I can follow? Is this a major undertaking?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为 @traviscline 建议使用 pymysql 欢呼三声。他的建议基于 mozilla 的这篇文章 。所需要的只是对manage.py文件进行简单的修补,
更改导入你的设置文件和monkeypatch(),因为pymysql是一个纯Python驱动程序。
travis 提到,他通过更改导入并运行 pymysql、mysqldb 和 myconnpy 的单元测试来测试兼容性。
请注意,已经有需要注意的更精细细节的示例 - 但总的来说,这是一个优雅的、可维护的解决方案。当我在生产环境中运行时我会更新!
three cheers for @traviscline's suggestion to go with pymysql. his suggestion was based on this post from mozilla. all it takes is a simple patch to your manage.py file
changing the import in your settings file, and monkeypatch() since pymysql is a pure python driver.
travis mentioned that he tests for compatability by changing the imports and running the unittests for pymysql, mysqldb, and myconnpy.
note that there are already examples of finer details to watch out for - but overall this is an elegant, maintainable solution. i will update when i get this running in production!
我成功地让 pymysql 与 Django 一起工作,执行以下操作:
将以下四行添加到base.py
<前><代码>尝试:
导入 pymysql 作为数据库
除了导入错误:
经过
如链接中所述 egbutter 已发布,转到 base.py 文件并在文件的相关部分将
MySQLdb
替换为pymysql
,即不必打扰更改错误消息(您可以,但这取决于您)。保存base.py,并从apt位置运行以下命令以查看服务器启动。
I was successful in getting pymysql to work with Django doing the following :
Add the following four lines to base.py
As mentioned in the link that egbutter posted, go to the base.py file and find-replace
MySQLdb
withpymysql
at relevant portions of the file, i.e. don't bother changing the error messages (you could, but that's up to you).Save base.py, and run the following command from the apt location to see the server start up.