Goun2
Goun2

Reputation: 437

How to make a function run along with my views

I have this function, I want it to be working with my view, how could I do it ?

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

Upvotes: 0

Views: 194

Answers (1)

Alasdair
Alasdair

Reputation: 308779

If PlaySound is not a method of a class, then you don't need self. use def PlaySound():.

def PlaySound():
    ...

You can then call the method in the view, before you return the response.

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

Upvotes: 1

Related Questions