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!

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 Final Details Article detail view

Article Detail View, Question 1 of 3.

when I enter this code for the first challenge:

from .models import Step

def article_detail(request, pk): step = get_object_or_404(Step, id=pk, pk=step_pk) return render(request, 'articles/article_detail.html', {'step': step})

I get "Bummer! Did you create the 'article_detail view?" Well, yeah...that's what I was trying t do...

Any help? Thanks.

from django.shortcuts import render

from .models import Article, Writer
from .models import Step

def article_list(request):
    articles = Article.objects.all()
    return render(request, 'articles/article_list.html', {'articles': articles})

def writer_detail(request, pk):
    writer = Writer.objects.get(pk=pk)
    return render(request, 'articles/writer_detail.html', {'writer': writer})

def article_detail(request, pk):
    step = get_object_or_404(Step, id=pk, pk=step_pk)
    return render(request, 'articles/article_detail.html', {'step': step})
from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'writer/(?P<pk>\d+)/$', views.writer_detail),
    url(r'', views.article_list),

3 Answers

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

I think it might be your step import and use of that that's throwing off the challenge. I think you're going above and beyond what they're expecting. Take a look at my solution for step 1.

def article_detail(request, pk):
  article = Article.objects.get(pk=pk)
  return render(request, 'articles/article_detail.html',{'article': article})

Note: I did not import Step either.

Thanks...I figured it out right after I posted. Shouldn't be so impatient! Now I'm "stuck" on step 3.

Thanks again for responding so quickly.

OK...I just said I should be more patient. But I think I must be missing something really basic for the 3rd question:

def article_detail(request, pk): article = Article.objects.get(pk=pk) article = get_object_or_404(Article, pk=pk) return render(request, 'articles/article_detail.html',{'article': article})

The message says to be sure that bad pk's are returning 404's Seems like this is how he did it in the video...

Thanks again.

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Honestly? I have no idea LOL. I can't make it past it again either. I can do step one and 2 but fail on step 3. I'd suggest posting a whole new question and let someone with more points/experience than I have answer that one :)

Thanks...I actually think there's a bug. :)