Django – Display hyperlinks in templates

I had a couple of challenges here apart from just displaying hyperlinks.

1. Displaying the hyperlinks
2. Filter the list of display data to show hyperlink for first item and not for rest

<table class="sortable">
  <tr>
    {% for column in report_header %}
      <th>{{column}}</th>
    {% endfor %}
  </tr>
  {% for row in report_body %}
    <tr class="{% cycle "row1" "row2" %}">
      {% for column in row %}
        {% if forloop.counter == 1 %}
          {% with row.0|urlencode as encoded_name %}
            <td><a href="#" onclick="window.open('{%url showAccountPage encoded_name%}', '_blank');">{{row.0}}</a></td>
          {% endwith %}
        {% else %}
            <td>{{column}}</td>
        {% endif %}
      {% endfor %}
    </tr>
  {% endfor %}
</table>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s