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 trialNursultan Bolatbayev
16,774 PointsWhere we should include url for views?
When we create view, we have to include this view in url file. But do we need to create new url file under app folder and that new url file will be included in root urls.py file under project folder or we can include it in existing urls.py file under project folder straightforward ? Which one is the best practice?
2 Answers
Kenneth Love
Treehouse Guest TeacherIt depends on the context of the URL. If it's a view that's specific to an app (most views are), then, yes, put it into the urls.py
in your app. If it's something more site-wide, like maybe an About page or something, it's fine to put it into the project's urls.py
.
Julian Garcia
18,380 PointsHi as far as know, the most common is to create a urls.py in applications folder and include that file in
the project
s urls.py
project
----app_name
--------urls.py
----project_folder
--------urls.py
in project`s urls.py:
urlpattern = [
url(r'^app_name/', include(app_name.urls)),
....
]
That is what I use in my projects.
Nursultan Bolatbayev
16,774 PointsYes, this is what I saw in another source too. But in the video Kenneth Love includes it straightforward into urls.py file under project folder. And what is difference doing in that way? Does it affect anything?
Nursultan Bolatbayev
16,774 PointsNursultan Bolatbayev
16,774 PointsI see. Now it is a bit clear. Thanks!