使用 Django 减去 Web 服务器
我正在编写一个联合客户端,目的是拥有一个设备客户端和一个具有相同功能的网站。我将使用 Django 开发网站 - 这已经决定了;客户端应使用 Python 编写,并带有 CLI 和 PyQt4 GUI。我首先编写了 clinet,它的数据库量相当大,因为所有内容都被缓存以使其能够在离线时读取。
今天我突然意识到,在我的应用程序中使用 Django 模型是有意义的,可以减少客户端和网站之间的重复工作。我的问题是分离它有多容易,以及我的客户端需要多少 Django 才能使用 Django 的模型。据我所知,我不需要运行服务器,但是还需要什么?我有一个想法,为我的客户生成与网站相同的 html,但使用 Qt 小部件显示它,而不是为浏览器提供页面。
以前有人尝试过这种事情吗?我已经开始这样做了,但是最好能得到关于潜在死胡同或会造成维护噩梦的事情的警告......
I'm writing a syndication client, with the aim being to have a client for devices, and a web site that has the same functionality. I shall develop the website using Django - this is already decided; the client shall be written in python with both a CLI and a PyQt4 GUI. I have been writing the clinet first, and it's fairly database-heavy, as everything is cached to enable it to be read while offline.
It struck me today that it would make sense to use Django models for my application, to reduce the repetition of effort between the client and the website. My question is how easy it is to seperate this, and how much of Django I will need in my client to use Django's models. AFAIK I should not need to run the server, but what else is needed? I had an idea of generating the same html for my client as the website, but showing it withing Qt widgets rather than serving pages for a browser.
Has anyone tried this sort of thing before? I'm starting on this already, but it would be good to get a warning of potential dead-ends or things that will create a maintainance nightmare...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
阅读独立 Django 脚本,您就会发现将踏上你的胜利之路。基本上你真正要做的就是引用 Django settings.py (Django 期望的),然后 使用没有 Web 视图或 URL 的模型。
如果您真正感兴趣的是使用 Django 的 ORM 来管理模型和数据库交互,您可能需要考虑使用 SQLAlchemy< /a> 相反。
Read up on standalone Django scripts and you'll be on your path to victory. Basically all you're really doing is referencing the Django settings.py (which Django expects) and then using models without web views or urls.
If all you're really interested in is using Django's ORM to manage your models and database interaction, you might want to consider using SQLAlchemy instead.
您仍然需要将 Django 应用程序作为 Web 服务器运行,但您可以将其限制为仅服务于 localhost 或其他内容。当然,您可以使用 QtWebKit 作为客户端。
You'll still have to run the Django app as a web server, but you can restrict it to serve to only localhost or something. And sure, you can use QtWebKit as the client.