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 trialJohnathan Stevens
361 PointsNot working
Why is this not working?
from django.shortcuts import render
from .models import Article, Writer
def article_list(request):
articles = Article.objects.all()
return render(request, 'articles/article_list.html', {'articles': articles})
def writer_detail(request, pk):
getPk = Writer.objects.get(pk=pk)
return render(request, 'articles/writer_detail.html', {'writer': getPK})
2 Answers
Kenneth Love
Treehouse Guest TeacherThe grader doesn't care about the variable names in the view. The original code is failing because getPk
(the first line in the view), and getPK
(in the context dictionary), are not the same variable. The context dictionary's getPK
doesn't exist.
Chris Freeman
Treehouse Moderator 68,454 PointsSorry in advance. Your code is correct, but the grader is uber-picky. It is looking for . Changing to writer
as the variable name and for some reason doesn't like getPk
writer
passes the challenge:
def writer_detail(request, pk):
writer = Writer.objects.get(pk=pk)
return render(request, 'articles/writer_detail.html', {'writer': writer})
Edit: Didn't see typo in OP. Deferring to Kenneth's correct answer.
Chris Freeman
Treehouse Moderator 68,454 PointsTagging Kenneth Love to check if the challenge grader for Writer View can be relaxed to allow different variable names.
Chris Freeman
Treehouse Moderator 68,454 PointsChris Freeman
Treehouse Moderator 68,454 PointsYep! You are correct again! I missed the typo and jump way to far to a false conclusion.
Maybe it's time to add flake8 or pylint to the grader results to catch these errors.
Marking best answer!