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?
Absolutely, yes. In fact, Flask is arguably better for a truly large scale app compared to Django. Django is more for medium-sized apps that fit a standard template.
Flask is a good start if you are getting into web development. There are many websites built on the flask and gain heavy traffic, but not as much compared to the ones in Django. Django is not suitable for projects where requirements change dynamically.
If you wish to develop a simple and lightweight web application then Flask is suitable for that. It is not as powerful and extensive as Django but still provides features such as support for unit testing and building REST APIs. Learning Flask will take 1 – 1.5 weeks.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With