Question
How does one execute a Django view.py print function from a HTML button?
Senario
I have a start button on the front end of my project which when clicked by the user is meant to direct them to one of several survey tasks to be completed. This will be a random selection though once any one of the tasks has been completed e.g. 50 times it will be taken out of the sequence.
Currently I'm just trying to get the below function to print the number 8 in Terminal as a first step in learning how to call/execute a Django/Python function based on the users interaction with the front end.
I have looked at several questions here including Django: How can I call a view function from template? which suggest wrapping the button in a form but I cant seem to get any of the answers to work. I would prefer not to put any of the logic into the HTML page.
This is my attempt so far. It currently dose not print to Terminal.
HTML in a bootstrap front end
<form method="get">
<input type="submit" value="START" name="mybtn" id="start_submit" class="btn btn-success"/>
</form>
Print Function in views.py
def request_page(request):
if(request.GET.get('mybtn')):
counter = 8
print counter
return render_to_response('selected_path.html')
My overall issue is that everything I have learned so far with Django/Python has involved the creation of various functions and simply adding the necessary template tags to the HTML page to show the content or interactive element. I'm just not sure how to go about doing it the other way round, building front end facilities to call on the back end.... I hope that makes sense.
Thanks