This is as I understand the way Django works.
From the address bar in the browser the urls.py is searched for a matching address.
If address is found the next step is access a def() in the views.py
The def() does stuff and passes data back to the web page.
What I want to do, and failing to understand the mechanism to do so, is to take two input dates from the web page and pass them to the views.def(). Does submit on the web page store more that one data entry. If so, how does this work?
test.html
{% extends 'base.html' %}
{% block content %}
<br /><br />
<form action="" method="get">
<label for="from">Start Date</label>
<input type="text" name="start_date"><br /><br />
<label for="to">End Date </label>
<input type="text" name="end_date"><br />
<input type="submit" value="Submit">
</form>
<p>{{ s_date }}</p>
<p>{{ e_date }}</p>
{% endblock %}
views.py
def Test(request):
if 'start_date' in request.GET:
s_date = request.GET['start_date']
e_date = request.GET['end_date']
else:
s_date = None
e_date = None
context = {"s_date": s_date, "e_date": e_date}
return render_to_response('test.html', context, context_instance=RequestContext(request))
On the Stackoverflow message Passing objects from template to view using Django method="post" is used. As I only want to read the data would method="get" be better?
Just in case, the dates are stores in yyyy-mm-dd format.
The function is working. I would like to know what I am missing regarding the passing of the variables from template to function.
Thank you.