是否可以使用Django和Node.Js?

时间:2022-11-10 20:56:34

I have a django backend set up for user-logins and user-management, along with my entire set of templates which are used by visitors to the site to display html files. However, I am trying to add real-time functionality to my site and I found a perfect library within Node.Js that allows two users to type in a text box and have the text appear on both their screens. Is it possible to merge the two backends?

我有一个django后端设置用户登录和用户管理,以及我的整个模板集,网站的访问者使用它来显示html文件。但是,我正在尝试向我的网站添加实时功能,我在Node.Js中找到了一个完美的库,允许两个用户输入文本框并在其屏幕上显示文本。是否有可能合并两个后端?

4 个解决方案

#1


9  

It's absolutely possible (and sometimes extremely useful) to run multiple back-ends for different purposes. However it opens up a few cans of worms, depending on what kind of rigour your system is expected to have, who's in your team, etc:

为不同目的运行多个后端绝对是可能的(有时非常有用)。然而,它会打开一些蠕虫,取决于您的系统预期会有多严格,谁在您的团队中等等:

  • State. You'll want session state to be shared between different app servers. The easiest way to do this is to store external session state in a framework-agnostic way. I'd suggest JSON objects in a key/value store and you'll probably benefit from JSON schema.
  • 州。您希望在不同的应用服务器之间共享会话状态。最简单的方法是以框架无关的方式存储外部会话状态。我建议在键/值存储中使用JSON对象,您可能会从JSON模式中受益。
  • Domains/routing. You'll need your login cookie to be available to both app servers, which means either a single domain routed by Apache/Nginx or separate subdomains routed via DNS. I'd suggest separate subdomains for the following reason
  • 域/路由。您需要两个应用服务器都可以使用您的登录cookie,这意味着Apache / Nginx路由的单个域或通过DNS路由的单独子域。我建议使用单独的子域名,原因如下
  • Websockets. I may be out of date, but to my knowledge neither Apache nor Nginx support proxying of websockets, which means if you want to use that you'll sacrifice the flexibility of using an http server as a app proxy and instead expose Node directly via a subdomain.
  • WebSockets的。我可能已经过时了,但据我所知,Apache和Nginx都不支持代理websockets,这意味着如果您想使用它,您将牺牲使用http服务器作为应用程序代理的灵活性,而是直接通过子域。
  • Non-specified requirements. Things like monitoring, logging, error notification, build systems, testing, continuous integration/deployment, documentation, etc. all need to be extended to support a new type of component
  • 非指定要求。监控,日志记录,错误通知,构建系统,测试,持续集成/部署,文档等等都需要扩展以支持新类型的组件
  • Skills. You'll have to pay in time or money for the skill-sets required to manage a more complex application architecture
  • 技巧。您需要花时间或金钱来支付管理更复杂的应用程序架构所需的技能

So, my advice would be to think very carefully about whether you need this. There can be a lot of time and thought involved.

所以,我的建议是仔细考虑你是否需要这个。可能会有很多时间和思想。

Update: There are actually companies springing around who specialise in adding real-time to existing sites. I'm not going to name any names, but if you look for 'real-time' on the add-on marketplace for hosting platforms (e.g. Heroku) then you'll find them.

更新:实际上有些公司专注于为现有网站添加实时性。我不打算命名任何名字,但如果你在主机平台(例如Heroku)的附加市场上寻找“实时”,那么你会发现它们。

Update 2: Nginx now has support for Websockets

更新2:Nginx现在支持Websockets

#2


2  

You can't merge them. You can send messages from Django to Node.Js through some queue system like Reddis.

你无法合并它们。您可以通过Reddis等队列系统将消息从Django发送到Node.Js。

#3


0  

If you really want to use two backends, you could use a database that is supported by both backends.

如果您确实想要使用两个后端,则可以使用两个后端都支持的数据库。

Though I would not recommended it.

虽然我不推荐它。

#4


0  

Try Django, Node.js, Socket.io and Reddis.

试试Django,Node.js,Socket.io和Reddis。

#1


9  

It's absolutely possible (and sometimes extremely useful) to run multiple back-ends for different purposes. However it opens up a few cans of worms, depending on what kind of rigour your system is expected to have, who's in your team, etc:

为不同目的运行多个后端绝对是可能的(有时非常有用)。然而,它会打开一些蠕虫,取决于您的系统预期会有多严格,谁在您的团队中等等:

  • State. You'll want session state to be shared between different app servers. The easiest way to do this is to store external session state in a framework-agnostic way. I'd suggest JSON objects in a key/value store and you'll probably benefit from JSON schema.
  • 州。您希望在不同的应用服务器之间共享会话状态。最简单的方法是以框架无关的方式存储外部会话状态。我建议在键/值存储中使用JSON对象,您可能会从JSON模式中受益。
  • Domains/routing. You'll need your login cookie to be available to both app servers, which means either a single domain routed by Apache/Nginx or separate subdomains routed via DNS. I'd suggest separate subdomains for the following reason
  • 域/路由。您需要两个应用服务器都可以使用您的登录cookie,这意味着Apache / Nginx路由的单个域或通过DNS路由的单独子域。我建议使用单独的子域名,原因如下
  • Websockets. I may be out of date, but to my knowledge neither Apache nor Nginx support proxying of websockets, which means if you want to use that you'll sacrifice the flexibility of using an http server as a app proxy and instead expose Node directly via a subdomain.
  • WebSockets的。我可能已经过时了,但据我所知,Apache和Nginx都不支持代理websockets,这意味着如果您想使用它,您将牺牲使用http服务器作为应用程序代理的灵活性,而是直接通过子域。
  • Non-specified requirements. Things like monitoring, logging, error notification, build systems, testing, continuous integration/deployment, documentation, etc. all need to be extended to support a new type of component
  • 非指定要求。监控,日志记录,错误通知,构建系统,测试,持续集成/部署,文档等等都需要扩展以支持新类型的组件
  • Skills. You'll have to pay in time or money for the skill-sets required to manage a more complex application architecture
  • 技巧。您需要花时间或金钱来支付管理更复杂的应用程序架构所需的技能

So, my advice would be to think very carefully about whether you need this. There can be a lot of time and thought involved.

所以,我的建议是仔细考虑你是否需要这个。可能会有很多时间和思想。

Update: There are actually companies springing around who specialise in adding real-time to existing sites. I'm not going to name any names, but if you look for 'real-time' on the add-on marketplace for hosting platforms (e.g. Heroku) then you'll find them.

更新:实际上有些公司专注于为现有网站添加实时性。我不打算命名任何名字,但如果你在主机平台(例如Heroku)的附加市场上寻找“实时”,那么你会发现它们。

Update 2: Nginx now has support for Websockets

更新2:Nginx现在支持Websockets

#2


2  

You can't merge them. You can send messages from Django to Node.Js through some queue system like Reddis.

你无法合并它们。您可以通过Reddis等队列系统将消息从Django发送到Node.Js。

#3


0  

If you really want to use two backends, you could use a database that is supported by both backends.

如果您确实想要使用两个后端,则可以使用两个后端都支持的数据库。

Though I would not recommended it.

虽然我不推荐它。

#4


0  

Try Django, Node.js, Socket.io and Reddis.

试试Django,Node.js,Socket.io和Reddis。