Search code examples
pythonflaskcoding-stylestandardsproject-structure

Is it bad practice to write a whole Flask application in one file?


I'm currently writing a web application in Python using the Flask web framework. I'm really getting used to just putting everything in the one file, unlike many other projects I see where they have different directories for classes, views, and stuff. However, the Flask example just stuff everything into the one file, which is what I seem to be going with.

Is there any risks or problems in writing the whole web app in the one single file, or is it better to spread out my functions and classes across separate files?


Solution

  • Usually it's not a good practice to keep your app in a single file except that it's trivial or for educational purposes.

    I don't want to reinvent the wheel, so here's links for sample flask project structures, skeletons and other info on the subject:

    And, or course, read the awesome flask mega-tutorial - you'll see how your application will grow and split into logical parts step-by-step.