如何在 Django 框架中执行 python 脚本?

how to execute python script in django framework?

我只是想在 django 2 中执行 python 脚本。python 脚本将与 R305 指纹扫描仪通信。如果我按下网页中的按钮,它会执行 python 脚本并启动传感器。

需要帮助!

最快的实现方式是在模板中使用表单 post 以在按下按钮时触发脚本。

答案:

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.