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 trial

Python Django Forms Forms Showing a Form in a View

Simon Amz
Simon Amz
4,606 Points

Why the forms.py file has to be created in the project directory instead of the app directory ?

Why the forms.py file has to be created in the project directory instead of the app directory (here in 'learning_site' instead of 'courses' directory) ?

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You are correct, in that, the view and forms could have been placed in the courses directory. It depends how one wishes to organize the views. Since Kenneth started off by placing the URL under '/suggest/' and not '/courses/', then the new code doesn't need to go in the courses directory. Once the URL is defined, where the view goes should logically follow and the form will go in the forms.py relative to the views.py altered.

Post back if you have more questions. Good luck!!

Simon Amz
Simon Amz
4,606 Points

Hi Chris got it! So as forms.py contains the class SuggestionForm, it is placed according to the route defined, here 'suggest/'.

In the same way, we could have created a new app "suggestion" with a file url in it and with the forms.py too, right?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Correct. Sometimes utility functionality is lumped at the top level until sufficient content and an obvious partition leads to separating it into a new app.

Simon Amz
Simon Amz
4,606 Points

that's clear.

Thanks