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

Jianan Li
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jianan Li
Python Web Development Techdegree Graduate 27,747 Points

When quotation marks in 'include'?

When adding url to urlpatterns, and using include, when should we have quotation marks around the reference to urls, and when should not? Example:

urlpatterns = [
    url(r'^api/v1/courses/', include('courses.urls')),
    url(r'^api/v2/', include(router.urls))
]

I kind of see why one gets quotations, and one does not, since courses is in another module, while router is defined in this same file. But, can someone explain what's the rule and why?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 67,989 Points

I think you state it correctly. When the include uses quotes, the actual urls are to be looked up in a different module. Without the quotes, it is interpreted as a python object. In this case the router object has a urls attribute that contains the relevant urls to use.

This is similar to how the quoted 'name' is just a string of four characters but without quotes name is a variable that is looked up in the current namespace for its object reference.