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

article_detail view failing

I'm at a loss as to why this is failing. The only error message it seems to generate is 'Bummer! Try again!' which is supremely unhelpful in trying to track down what the problem is.

The instructions are:

We need to be able to view a single article. In articles/views.py, create a view named article_detail that takes a pk. The view should return the "articles/article_detail.html" template. Assign the Article to the article key in the context dictionary.

Which seems to involve just creating an article_detail view the same as the provided writer_detail view.

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):
    writer = Writer.objects.get(pk=pk)
    return render(request, 'articles/writer_detail.html', {'writer': writer})


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

Edit: added code, submit form said it was going to attach it but it didn't seem to.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,454 Points

It's possible the challenge checker might be throwing false errors. There are other Django challenge posts in the forum that are failing for unknown reasons. Stay tuned.

5 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

Your code is now passing. There was a temporary glitch in the challenge checker! Keep up the good work!

Dat Le Tran
Dat Le Tran
633 Points

Please fix it, the challenge checker is having the same problem again.

It's a waste of my time to check why I can't pass the challenge.

Treehouse has a bug on the third exercice.

Here is the solution

from django.shortcuts import render, get_object_or_404 from django.http import Http404

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): writer = Writer.objects.get(pk=pk) return render(request, 'articles/writer_detail.html', {'writer': writer})

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

Looks like you need to add the get_object_or_404 and use it instead of Artciles.objects.get(pk=pk)

this was my code for this challenge but yet its calling me a Bummer!, i have checked for errors yet Bummer! keeps appearing please any hint?

===========Article views===========

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 article_detail(request, pk):
    article = Article.object.get(pk=pk)
    return render(request, 'articles/article_detail.html', {'article': article})

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

in my challenge i was asked to do this """ We need to be able to view a single article. In articles/views.py, create a view named article_detail that takes a pk. The view should return the "articles/article_detail.html" template. Assign the Article to the article key in the context dictionary."""

[MOD: added ```python formatting -cf]

Thanks a lot v done that ...