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 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
Ian Salmon
Courses Plus Student 10,685 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.