django start python function when pressing button

Solutions on MaxInterview for django start python function when pressing button by the best coders in the world

showing results for - "django start python function when pressing button"
Rose
06 Jan 2021
1index.html
2
3<form method="post">
4    {% csrf_token %}
5    <button type="submit" name="run_script">Run script</button>
6</form>
7
8views.py
9
10if request.method == 'POST' and 'run_script' in request.POST:
11
12    # import function to run
13    from path_to_script import function_to_run
14
15    # call function
16    function_to_run() 
17
18    # return user to required page
19    return HttpResponseRedirect(reverse(app_name:view_name)