Search code examples
pythonhtmldjangodjango-templatesxlwt

Pass a GET parameter from HTML and receive in Django View


I'm trying to pass a start date and end date from my html href to my views.py

But I can't get the data related the passed date

Example: {{ date }} = 2021-05-13 {{ date1 }}= 2021-05-14

HTML:

<a href="{% url 'pba_defect_xls' %}? date = {{ date }}, date1 = {{ date1 }}" class="btn btn-success"  style="float:right;">Export Excel</a>

View:

def pba_defect_xls(request):
    if request.method == 'GET':
        date = request.GET.get('date')
        date1 = request.GET.get('date1')
        print(date)
        print(date1)

URLS:

path('pba_defect_xls', pba_defect_xls, name="pba_defect_xls"),

Howerver it's printing: date = None, date1 = None

The correct output should be: date = 2021-05-13, date1 = 2021-05-14

The aim of this code is retrieve the date to export to excel by xlwt in django

Any ideal about this issue?


Solution

  • something like this should works:

    <a href="{% url 'pba_defect_xls' %}?date={{ date }}&date1={{ date1 }}" class="btn btn-success"  style="float:right;">Export Excel</a>