2012-08-07 69 views
1

我的服務器上安裝了節點。我想執行一個基本上從Django模型中獲取信息的JavaScript文件。我如何將JSON和大型textarea變量從Django內部傳遞到我的節點腳本中?節點(和Django)的服務器端JavaScript

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? 

謝謝!

+0

我看到的關鍵字少和HTML。你期望節點完全做什麼? – travis 2012-08-07 22:38:03

+0

@travis我只是把它當作一個想到的簡單例子。在這個例子中,我想編譯一個較少的模板服務器端並使用html進行渲染。 – zallarak 2012-08-07 22:39:22

回答

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."