0

I have this following dictionary:

results[calendar.month_name[date_cursor.month]] =  [e,z]

My url is:

    url(r'^company/(?P<pk>\d+)/purchasedelete/(?P<month>\d+)/date/(?P<pk3>\d+)/$',views.purchase_register_datewise,name='purchase_datewise'),

My view:

def purchase_register_datewise(request,month,pk,pk3):
    company_details = get_object_or_404(Company, pk=pk)
    selectdatefield_details = get_object_or_404(Selectdatefield, pk=pk3)

    result = Purchase.objects.filter(Company=company_details.pk, date__month=month, date__gte=selectdatefield_details.Start_Date, date__lt=selectdatefield_details.End_Date)



    context = {

        'company_details'             : company_details,
        'selectdatefield_details'     : selectdatefield_details,
        'result'                      : result, 

    }

    return render(request, 'stockkeeping/purchase/Purchase_Register_Datewise.html', context)

In my template:

        {% for key, value in data %}
          <tr>
            <td><center><a href="{% url 'stockkeeping:purchase_datewise' pk=company_details.pk month={{ key }} pk3=selectdatefield_details.pk %}"></a>{{ key }}</center></td>

            {% if value.0 == 0 %}
              <th><center></center></th>
            {% else %}
              <td><center>{{ value.0 }}</center></td>
            {% endif %}

            <th><center></center></th>
            {% if value.1 == 0 %}
              <th><center></center></th>
            {% else %}
              <td><center>{{ value.1 }} Dr</center></td>
            {% endif %}
          </tr>
        {% endfor %}

When I try to do month={{ key }}

It throws me a error like this Could not parse the remainder: '{{' from '{{'

Can anyone tell me how to pass the value of key in my template.

Thank you

Niladry Kar
  • 1,163
  • 4
  • 20
  • 50
  • Possible duplicate of [django 1.5 - How to use variables inside static tag](https://stackoverflow.com/questions/16655851/django-1-5-how-to-use-variables-inside-static-tag) – Ivan Starostin Apr 10 '19 at 13:31
  • I have not found my solution there @IvanStarostin – Niladry Kar Apr 10 '19 at 13:33
  • 1
    Try month=key? You can't use template tags inside template tags. – RemcoGerlich Apr 10 '19 at 13:35
  • You use `month=key` just as you did `pk3=selectedatefield_details.pk`. – Daniel Roseman Apr 10 '19 at 13:37
  • Yeah the value comes after doing `month=key` but its not rendering me to the desired page,. Can you tell me why?I have updated my question – Niladry Kar Apr 10 '19 at 13:46
  • Have you manually checked the url? Is the `month` parameter actually causing the problem? – Willy Apr 10 '19 at 17:29
  • Yeah I get it now the `month` parameter is taking integer value of months when I remove `calendar.month_name[date_cursor.month]` to only `date_cursor.month` it works fine... Thank you everyone for the help. – Niladry Kar Apr 11 '19 at 05:29

0 Answers0