2017-05-10 16 views
0

我有这个功能,我希望它能与我的观点一起工作,我该怎么做?如何使功能与我的观点一起运行

def PlaySound(self): 
    while(True): 
     if GPIO.input(Snare) == False: 
     os.system("path/to/the/sound") 
    return ("Is activated") 

def view(request): 
    return render(request, "page.html") 
+0

你为什么不能直接叫它? –

+0

我该怎么做? – Goun2

+0

与其他功能相同:'PlaySound()'。 –

回答

1

如果PlaySound是不是一类的方法,那么你不需要self。使用def PlaySound():

def PlaySound(): 
    ... 

然后,您可以在返回响应之前调用视图中的方法。

def view(request): 
    PlaySound() 
    return render(request, "page.html") 
+0

PlaySound需要非常大的1个参数(0给定),但是我的函数不需要参数 – Goun2

+0

如果你得到这个错误,那么你没有改变'def PlaySound(self):'到'def PlaySound():'建议。 – Alasdair

+0

好的,我会尝试,谢谢 – Goun2

相关问题