Tutorial :Template in Django



Question:

Inline template

In my template can I use a <a href> tag? I want that if there is a field named 'id' it should give a href link over there. I have tried following options:

1){% ifequal field.field.label "Id" %}

<a href =../../{{field.field}}>click here </a>  

2){% ifequal field.field.label "Id" %}

<a href ="../../{{field.field}}">click here </a>  

3){% ifequal field.field.label "Id" %}

<a href =../../{{field.field.value}}>click here </a>  

4){% ifequal field.field.label "Id" %}

<a href ="../../"{{field.field}}>click here </a>  

5){% ifequal field.field.label "Id" %}

<a href ={{field.field}}>click here </a>  

In this case it is showing the address of the current page. Means not showing the value of field.field.

All the options do not work. It is not showing the value of field.field in href.field.field.label shows Id in href when I displays the value field.field

{{field.field}} it is showing correct value.


Solution:1

Use {% url %} instead of composing your own href values.


Solution:2

I'd say {% if field.id %} {%endif%} should be enough (or field.field.id or field.field, depending on what's the inner structure).


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »