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 Django Templates Writer view

Johnathan Stevens
Johnathan Stevens
361 Points

Not working

Why is this not working?

articles/views.py
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
STAFF
Kenneth Love
Treehouse Guest Teacher

The 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
Chris Freeman
Treehouse Moderator 68,426 Points

Yep! 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! :+1:

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

Sorry in advance. Your code is correct, but the grader is uber-picky. It is looking for writer as the variable name and for some reason doesn't like getPk. Changing to 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
Chris Freeman
Treehouse Moderator 68,426 Points

Tagging Kenneth Love to check if the challenge grader for Writer View can be relaxed to allow different variable names.