Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a relatively simple web application that is written in Python using the Flask microframework. I've really enjoyed Flask's ease of use, however, as the app has grown larger it has started to become unwieldy having all of my actions (and utility functions) in a single file. My is about 700 lines of code and I'd really like to break things out into more discrete units. How should I restructure my code?

share|improve this question
up vote 5 down vote accepted

There are multiple ways to structure your application:

  1. The easiest is just to stick to the functions and move them to different files. For as long as you make sure they are imported when the application starts that's perfectly okay.
  2. Use Blueprints to assign the views to “categories”. For instance backend, auth, profile, etc. Blueprints have the advantage that they can in theory be attached to multiple applications and are also a great way to implement application factories.
  3. Use the underlying Werkzeug URL map and register functions on there on a central URL map.

For all these topics there are entries in the pattern section of the Flask documentation.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.