【问题标题】:Server-side javascript with node (and Django)带有节点(和 Django)的服务器端 javascript
【发布时间】:2012-08-05 00:10:54
【问题描述】:

我的服务器上安装了节点。我想执行一个 JavaScript 文件,它基本上从 Django 模型中获取一些信息。如何从 Django 内部将 JSON 和大型 textarea 变量传递到我的节点脚本中?

class Page(models.Model):                
    html    = models.TextField(blank = True, null = True)                
    less    = models.TextField(blank = True, null = True)
    context = models.TextField(blank = True, null = True)

    def render(self):
        # pass context (converted to JSON), less and html to node script and compile.
        # How to do this?

谢谢!

【问题讨论】:

  • 我看到关键字less和html。您希望节点具体做什么?
  • @travis 我只是将其用作我想到的一个快速示例。在这个例子中,我想在服务器端编译一个 less 模板并用 html 渲染它。

标签: javascript python django node.js


【解决方案1】:

我是这样做到的:

import subprocess
...
command_list = ['node', 'static/js/node_script.js']

try:
  output = subprocess.check_output(command_list)
except subprocess.CalledProcessError:
  output = "Error in command_list."

【讨论】:

    猜你喜欢
    • 2012-07-08
    • 2016-06-03
    • 1970-01-01
    • 1970-01-01
    • 2020-05-27
    • 2021-04-13
    • 2016-08-06
    • 1970-01-01
    • 2016-03-20
    相关资源
    最近更新 更多