-1

I just wanted to execute python script in django 2. The python script will communicates with R305 fingerprint scanner. If i pressed a button in webpage, which executes the python script and initiates the sensor.

Need help!

Yogesh T S
  • 1
  • 1
  • 4

1 Answers1

0

The fastest way to implement this is to use a form post in your template to trigger the script on a button press.

Answer:

views.py

def press_my_buttons(request):
    if request.POST:
        # Run your script here
        print("Got the POST request")
    return render(request, 'my_template.html')

my_template.html

<form method="post">
    {% csrf_token %}
    <button type="submit">Press Me!</button>
</form>

Note: While this would get the job done, I would look into trying to use AJAX. Here is a link that could help.

Nihal
  • 5,262
  • 7
  • 23
  • 41
wrabbit
  • 196
  • 7