1

I'm trying to pass date input to django python script in order to retrieve the data based on it.

Here is my code.

view

def daily_usage_report(request):
    if request.method == 'POST':
        request_date = request.POST.get('request_date')
    else:
        request_date = date.today()

    print(request_date)
...

html

    <form method="post" action="#">
        <input type="date" name="request_date" id="request_date">
        <button class="btn btn-primary"><a href="{% url 'daily_usage_report' %}" style="color: white;">Daily Usage Report</a></button>
    </form>

I tried to fill the form with random date, but it keeps printing today date.

Ricky
  • 53
  • 6

2 Answers2

2

your html should be looking like this:

<form method="post" action="{% url 'daily_usage_report' %}">
    <input type="date" name="request_date" id="request_date">
    <input type="submit">
</form>
Iliano 920
  • 36
  • 3
0

You need to pass the python script file in the POST form method action in your HTML script.


<form method="post" action="python_script_goes_here.py">
        <input type="date" name="request_date" id="request_date">
        <button class="btn btn-primary"><a href="{% url 'daily_usage_report' %}" style="color: white;">Daily Usage Report</a></button>
</form>
Jamil Matheny
  • 180
  • 1
  • 7