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

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.