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 trialAlx Ki
Python Web Development Techdegree Graduate 14,822 PointsHow to rebuild Learning site for new Django 1.10.2?
Learning site works with Django 1.8.4 well, but doesn't with new Django 1.10.2.
Throws exceptions "NoReverseMatch" for views.
5 Answers
Tatiana Vasilevskaya
Python Web Development Techdegree Graduate 28,600 PointsReversing by dotted path was deprecated in Django 1.10. Just naming the view will solve the problem.
Kenneth Love
Treehouse Guest TeacherAh, yeah, IIRC, there was something like {% url "views.hello_world" %}
in a template, right? That's no longer supported as of Django 1.10, so you'll need to give the URL a name and use that instead, like Tatiana Vasilevskaya mentioned.
Kenneth Love
Treehouse Guest TeacherIf that's what you named the URL. url(r"^hello/$", views.hello_world, name="hello_world")
for example.
Alx Ki
Python Web Development Techdegree Graduate 14,822 PointsDone. Thank you.
Alx Ki
Python Web Development Techdegree Graduate 14,822 PointsThanks to Tatiana Vasilevskaya and Kenneth Love !
OK, so if someone else is interested in how to correct learning_site to use with Django 1.10:
1 In learning_site/urls.py add name to hello_world.
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from . import views
urlpatterns = [
url(r'^courses/', include('courses.urls', namespace='courses')),
url(r'^admin/', include(admin.site.urls)),
url(r'^$', views.hello_world, name='hello_world'),
]
urlpatterns += staticfiles_urlpatterns()
2 in layout.html change dot notation for hello_world to the name added.
{% load static from staticfiles %}
<!doctype html>
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" href="{% static 'css/layout.css' %}">
</head>
<body>
<div class="site-container">
<nav>
<a href="{% url 'hello_world' %}">Home</a>
<a href="{% url 'courses:list' %}">Courses</a>
</nav>
{% block content %}{% endblock %}
</div>
</body>
</html>
Kenneth Love
Treehouse Guest TeacherCan you provide any more detail?
Alx Ki
Python Web Development Techdegree Graduate 14,822 PointsOk.
- I use PyCharm.
- If i specify django version for my venv to 1.8.4 or 1.8.7 (You used 1.8.7 in video) - everything works like in video.
- If i instal latest django 1.10.2 to my venv - i get exceptions (i guess while rendering templates). Run manage.py Task: Exception in browser:
Same exception i get for all views.
Alx Ki
Python Web Development Techdegree Graduate 14,822 PointsAlx Ki
Python Web Development Techdegree Graduate 14,822 PointsHi, Tatiana Vasilevskaya ! What do you mean saying naming? Naming in views.py?
Tatiana Vasilevskaya
Python Web Development Techdegree Graduate 28,600 PointsTatiana Vasilevskaya
Python Web Development Techdegree Graduate 28,600 PointsSorry, naming the view url in urls.py and then use this name, when reversing to it.
Alx Ki
Python Web Development Techdegree Graduate 14,822 PointsAlx Ki
Python Web Development Techdegree Graduate 14,822 PointsDone! Thank You!