Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

Aaron Wise
Aaron Wise
7,517 Points

What to do they mean by "Make sure the URL is /article/<pk>/"

Heres the question from Django Basics: Add a new url to article/urls.py. The pattern should be "article/" and then the pk argument, which should be one or more digits.

I've got this code here:

from django.conf.urls import url

from . import views

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

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

2 Answers

Assuming you're referencing part two of this Challenge, you can add the requested article/pk as below:

from django.conf.urls import url

from . import views

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

Hope that helps!

Actualy, I think he may have been talking about task 3...I'm getting the same error for:

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})

Any ideas why this is no good? The error is that bad PK's should be caught by 404.

Thanks.