从django运行fabfile任务

时间:2012-06-06 11:23:09

标签: django fabric

我有一个结构任务,例如 -

def run_task():

#code here

从命令提示符处运行此任务:

fab -c env.fabricrc run_task -H hostnamr

如何从django运行此任务?我点击django app中网页上的按钮,它应该这样做。 我怎样才能做到这一点?

2 个答案:

答案 0 :(得分:1)

Here's the section关于如何使用fabric作为python模块/库而不使用fab命令来运行任务。

简短的例子:

from fabric.api import execute
#import your task if it is not in the same module, i.e.:
from mytasks import run_task

execute(run_task, hosts='hostname')

答案 1 :(得分:0)

我认为你应该把这个逻辑放在Django应用程序的某个地方。让run_task只是这个逻辑的包装。

这是基于应用程序的fabfile,反之亦然。