Question
How to execute print function of Django view.py using HTML button?
Senario
I have a start button on the front of my project, which when clicked by the user is designed to direct them to one of several shooting tasks that need to be completed. This will be a random choice, although as soon as any of the tasks is completed, for example. 50 times it will be deduced from the sequence.
I'm currently just trying to get the following function to type number 8 in the terminal as a first step in learning how to call / execute a Django / Python function based on user interaction with the interface.
I reviewed a few questions here, including Django: how can I call the view function from a template? who offer to wrap the button in the form, but I cannot seem to receive any of the answers to the work. I would prefer not to introduce any logic into the HTML page.
This is my attempt. Currently, the dose is not printed in the terminal.
HTML at the end of the bootstrap
<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 common problem is that all I have learned so far with Django / Python is the creation of various functions and simply adding the necessary template tags to an HTML page to display content or an interactive element. I just don’t know how to do this, on the contrary, creating front end points to trigger the back end ... I hope this makes sense.