Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 662
user1814016 Avatar asked May 01 '13 14:05

user1814016


People also ask

Can Flask handle large applications?

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.

Is Flask good for big projects?

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.

How long will it take to master Flask?

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.


1 Answers

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:

  • Flask: Large App how-to
  • https://github.com/italomaia/flask-empty
  • How to organize a relatively large Flask application?
  • Flask project structure
  • How do I Structure My Flask Applications

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.

like image 124
alecxe Avatar answered Sep 21 '22 03:09

alecxe