Public pages: If… Then

  1. Linking
  2. Public pages
  3. Topic template

If you take a look at post.html, there’s a potential problem with the author link. We link to the author’s home page, but homepage is an optional field. If the author doesn’t have a home page, that link will just go to the same page.

There’s a template tag for “if” to help with situations like this.

<p class="author">

{% if post.author.homepage %}

<a href="{{ post.author.homepage }}">{{ post.author }}</a>,

{% else %}

{{ post.author }}

{% endif %}

{{ post.date|date:"l, F jS, Y h:i a" }}

</p>

You can find other “ifs” at http://docs.djangoproject.com/en/dev/ref/templates/builtins/.

  1. Linking
  2. Public pages
  3. Topic template