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 Basics Final Details url Tag

Is there anything like this in Django 1.10 or is there another syntax for it? Thanks in advance.

Not able to use url Tag in Django 1.10

Why are you using Django 1.10?

Hey, I've downgraded since I couldn't solve this. Guess I'll keep using older versions.

4 Answers

Timothy Recker
Timothy Recker
12,086 Points

Apparently, the syntax for a URL Tag is different in Django 1.10 (just discovered this myself through painful confrontation with a NoReverseMatch error). Here's the solution that worked for me...

In the video, Kenneth uses the following URL Tag in the nav element of the layout.html template:

        <a href="{% url 'views.hello_world' %}">Home</a>

In Django 1.10, you should use a URL name in URL Tags instead of referencing your view via 'views.view_name'. First, update the relevant urlpattern in your main urls.py with a name of your choosing, like so (see the third url):

urlpatterns = [
    url(r'^courses/', include('courses.urls')),
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.hello_world, name='yournamehere'),
]

Then, replace the 'views.hello_world' part of the URL Tag with the name you supplied in your urls.py, like so:

        <a href="{% url 'yournamehere' %}">Home</a>

I realize you've already switched to Django 1.9, but I thought I'd share this anyways, as there's bound to be someone else going through this course that wants to know how to use URL Tags in the latest version of Django.

Thanks anyway, it's good to know it :)

Glenn Velupillai
Glenn Velupillai
7,697 Points

Thank you so much TImothy Recker for this workaround. You are the best! I needed this, and it now works. I may not see the big pink bar on the top of the page with the "home" button inside it, but it is still fine without the colored bar. I see the small "home" link on the top left. Thank you again for the share!

You are the best. keep up the answers. but django is always great. thanks again.

nuri jeon
nuri jeon
14,376 Points

Thank you so much <3<3

Denis Angulo
Denis Angulo
14,387 Points

Timothy Recker! Thank you for your response, you saved me a lengthy fight with the "NoReverseMatch" error. Upvoted!

Kaushal Patel
Kaushal Patel
250 Points

Thanks Timothy Recker It worked for me in 1.10,

Pratham Mishra
Pratham Mishra
14,191 Points

hey Timothy, great job man! This was some really good help.