Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

[Django] link isn't being rendered as a link

I'm trying to built a basic navigation. But the link isn't being display on the page as a link, but just as plain text. What is wrong with my code?

HTML template:

<div class="nav">
  <li>
    <ul><a href="{% url 'articles:list' %}"></a>News</ul>
  </li>
</div>

articles/urls.py

urlpatterns = [
    url(r'^$', views.article_list, name='list'),
    url(r'(?P<pk>\d+)/$', views.article_detail, name='detail'),
]

Browser, view-source. The link works here if I click it, but not on the actually page.

<!DOCTYPE html>
<html>
  <head>
    <title>MySite</title>
  </head>
  <body>
      <div class="nav">
          <li>
              <ul><a href="/articles/"></a>News</ul>
          </li>
      </div>
  </body>
</html>

1 Answer

Ryan S
Ryan S
27,276 Points

Hi csj,

One thing I notice is that you have your <ul> and <li> tags reversed. All list items should be inside the unordered list, not the other way around. Try fixing those on your templates and see if that helps.

Also, make sure that once you correct the list tags, the anchor element <a> contains all the text you want to become a link. Right now your anchor element is empty, so "News" will only display as plain text

<div class="nav">
  <ul>
    <li><a href="{% url 'articles:list' %}">News</a></li>
  </ul>
</div>

Good luck.

LOL, good spotted with the list tags :D And I can't believe I didn't notice that the text was outside the ancher tags. My head isn't on straight today... Thanks and happy holidays.