Im working on a simple web app - that turns on a led on a arduino.
I'v got it working, but the problem is i dont want for the page to redirect/refresh after i press the button.
So once again; after i press the button i just want it to start a python script and dont redirect to a other page or refresh the current page.
Do i need to implement ajax or is there any other way? Tried some stuff with ajax but couldnt get it to work.
Code:
# urls.py
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('app.urls')),
path(random_string(5), views.ledOn, name = "ledikaOn"),
path(random_string(5), views.ledOff, name= "ledikaOff"),
# views.py
def ledOn(request):
s.send(ledOnUkaz.encode('ascii')) # to poslje kodo "ukaz ON" v server
return render(request, 'home.html')
# home.html
<a class="btn btn-primary text-uppercase font-weight-bold bg-primary" href="{% url 'ledikaOn' %}" role="button">LED ON</a>