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 trialJaan Talvet
4,950 Pointsonly the word "Course" appears on /courses/1/ page. Where are the details?
Python Django course, video: 40782
learning_site/courses/urls.py:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.course_list),
url(r'(?P<course_pk>\d+)/(?P<step_pk>\d+)/$', views.step_detail),
url(r'(?P<pk>\d+)/$', views.course_detail),
]
learning_site/templates/layout.html:
{% load static from staticfiles %}
<!doctype html>
<html>
<head>
<title>{% block title %}{% endblock %}</title>
<!-- use a static tag instead of STATICURL if loation can change like on S3 -->
<link rel="stylesheet" href="{% static 'css/layout.css' %}">
</head>
<body>
<div class="site-container">
{% block content %}{% endblock %}
</div>
</body>
</html>
learning_site/courses/views.py:
from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from .models import Course, Step
def course_list(request):
courses = Course.objects.all()
return render(request, 'courses/course_list.html', {'courses': courses})
def course_detail(request, pk):
course = Course.objects.get(pk=pk)
course = get_object_or_404(Course, pk=pk)
return render(request, 'courses/course_detail.html', {'course':'course'})
def step_detail(request, course_pk, step_pk):
step = get_object_or_404(Step, course_id=course_pk, pk=step_pk)
return render(request, 'courses/step_detail.html', {'step':'step'})
learning_site/courses/templates/courses/course_details.html
{% extends "layout.html" %}
{% block title %} {{ course.title}} {% endblock%}
{% block content %}
<article>
<h2>{{ course.title }}</h2>
{{ course.description }}
<section>
{% for step in course.step_set.all %}
<h3>{{ step.title }}</h3>
{{ step.description}}
{% endfor %}
</section>
</article>
{% endblock %}
thanks!
4 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsIn your view, you are passing a literal string 'course
' in the context dict instead of the variable course
. Remove the quotes:
return render(request, 'courses/course_detail.html', {'course':course})
Chris Freeman
Treehouse Moderator 68,441 PointsAre you sure there are more details to show? What happens if you do the following:
python manage.py shell
>>> from .models import Course
>>> course_one = Course.objects.get(pk=1)
>>> print(course_one.title, course_one.description, course_one.step_set.count())
Jaan Talvet
4,950 Pointshello chris, thanks for the reply. using the shell as you suggested shows the correct steps listed. If you check 5:34 in the video, you'll see the step listed on the page. However mine doesn't show that.
Looks like i'm not the only one and it hasn't been answered yet:
Jaan Talvet
4,950 Pointsthanks, eagle-eye! that solved the issue.