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 trialJianan Li
Python Web Development Techdegree Graduate 27,747 PointsWhen 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
Treehouse Moderator 68,441 PointsI 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.