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 trialCubes School
Courses Plus Student 17,884 PointsIs 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
Cubes School
Courses Plus Student 17,884 PointsHey, I've downgraded since I couldn't solve this. Guess I'll keep using older versions.
4 Answers
Timothy Recker
12,086 PointsApparently, 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.
Cubes School
Courses Plus Student 17,884 PointsThanks anyway, it's good to know it :)
Glenn Velupillai
7,697 PointsThank 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!
abdullahimohamed3
12,537 PointsYou are the best. keep up the answers. but django is always great. thanks again.
nuri jeon
14,376 PointsThank you so much <3<3
Denis Angulo
14,387 PointsTimothy Recker! Thank you for your response, you saved me a lengthy fight with the "NoReverseMatch" error. Upvoted!
Kaushal Patel
250 PointsThanks Timothy Recker It worked for me in 1.10,
Paulo Longino
5,017 PointsThanks a lot
Pratham Mishra
14,191 Pointshey Timothy, great job man! This was some really good help.
tjgrist
6,553 Pointstjgrist
6,553 PointsWhy are you using Django 1.10?