Greetings everyone,
I watched @carltongibson give a talk at DjangoCon Europe on YouTube called Yak-shaving to Where the Puck is Going to Be. In his talk, Carlton talked about adding views into urls.py. At the end of the talk, he also advocated for adding forms next to the views they support.
I’m curious how many people ascribe to Carlton’s notion of combining some (or all) of the normal app modules (urls, forms, models, views, etc.) into fewer files (or even one file)? The primary benefit being locality of behavior and not having quite so many files open at once. While you get used to it, I rather dislike having three or more files open just to make some relatively simple changes and having related things scattered across files. Having one or two files open most of the time sounds appealing and could reduce cognitive burden while coding.
Carrying this line of thinking to an extreme, one might organize apps into components (probably) around a model or two. For example, if you were creating a large newspaper project with an authors
app, you might have an authors.py
file that has all the forms, views, and possibly even models all pertaining to authors. Inside the same app, you might have an awards.py
to keep track of all the rewards your authors have won over the years that is similarly self-contained. Maybe not the best example, but hopefully you get the idea. This approach is conceptually similar to how VueJS organizes it’s Single-File Components (i.e., the HTML, CSS, and JS are be in the same file), which people really seem to enjoy. Note, the above is just one possible (and purposefully extreme) example to explore the ideas that Carlton mentioned.
Is anyone else combining the modules in their app(s) into a single file? If so, how are you structuring your modules? I don’t have any experience developing medium or large size Django apps, these are just ideas I’d like to explore for an app I’m writing.