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 trialDillon Reyna
9,531 PointsWhy do we have a 'views.py' and 'urls.py' for both the project, and the app? How does this not conflict?
I'm super lost on this. How do you keep track of which one you're supposed to be editing at any given time?
Why not one master list instead of two separate ones?
1 Answer
Anthony Albertorio
22,624 PointsThink about the concept of pluggable apps. The reason we have them inside our main project is to increase our modularity. Each app should be stand alone. So, each app has it has its own views.py and urls.py which make them stand alone. You don't want to worry about someone else's code when adding the app to your page. It should just work.
When we include our app inside of our main project, we let Django know that "hey, this app has its own way of handling things. Refer to that." That way you don't have to worry about the internals of the pluggable app that you are using which was written by someone else. You can just add their urls.py to your main urls.py file and forget it.
Now what is a view? A view is just a function that does or returns something when it is called upon. So it gets a request and does a particular thing, then returns a response. Those requests are routed by the urls.py, which sends things based on the regex in the address bar and where you tell it to route the info. Anything that matches the regex will send it to the associated function in views.py.
Hope this helps.