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">
    {% for column in report_header %}
    {% endfor %}
  {% 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="'{%url showAccountPage encoded_name%}', '_blank');">{{row.0}}</a></td>
          {% endwith %}
        {% else %}
        {% endif %}
      {% endfor %}
  {% endfor %}

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s