[Django]-Create HTML button to run Python Script

5👍

you have to do some modifications:

In your HTML file:

<div>Relay 1:
  <form action= '{% url my_view_name%}' method="POST">
      <input type="submit" value="Toggle" id="toggle1" />
  </form>
</div>

in urls.py

url(r'whatever^$', 'core.views.my_view',name='my_view_name'),

In views.py:

def my_view(request):
    if request.method == 'POST':
        import set_gpio
        #Do your stuff ,calling whatever you want from set_gpio.py

    return #Something, normally a HTTPResponse, using django

Leave a comment