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 REST Framework Make the REST Framework Work for You Viewsets and Routers

Include Namespace

Copying from previous poster:

Django 2.0 Error: 'Specifying a namespace in include() without providing an app_name ' In Django 2.0 , I should specify app_name in order for routing to work, re_path(r'^api/v2/', include(router.urls, namespace='apiv2')), should I define it this way ?

re_path(r'^api/v2/', include((router.urls,'apiv2'), namespace='apiv2')),

Can you please provide more explanation

1 Answer

Ian Salmon
PLUS
Ian Salmon
Courses Plus Student 10,687 Points

You were so close. If you look at the error again, after, "Specifying a namespace in include() without providing an app_name" ..... you will see the sentence:

"Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead."

In your 'include' you should pass the router.urls as the pattern (which you got), but then pass the app_name ('courses', not 'apiv2').

Thanks! This helped me in V3 as well.