Answers for "django start python function when pressing button"

0

django start python function when pressing button

index.html

<form method="post">
    {% csrf_token %}
    <button type="submit" name="run_script">Run script</button>
</form>

views.py

if request.method == 'POST' and 'run_script' in request.POST:

    # import function to run
    from path_to_script import function_to_run

    # call function
    function_to_run() 

    # return user to required page
    return HttpResponseRedirect(reverse(app_name:view_name)
Posted by: Guest on April-30-2021

Code answers related to "django start python function when pressing button"

Python Answers by Framework

Browse Popular Code Answers by Language