Package and Module in Python for creating a Web App using Flask
Question: Currently, I am in process of coding a web interface for a company.

This web interface is based on python micro-framework Flask. I want to use MVC
principle to build this interface. And I have some questions in mind.

The model will contain the data for ORM-mapping with help of SQLAlchemy, no
problem there.  
The views is based on some html and css, I don't think there will be a problem
here either.

The controller on the other hand is kind of cumbersome.  
I want to separate the pages into module and the script application into
separate modules, and packed all these modules into a packages of controller
for example like:

  * Session Module (Login/Logout/Cookies)
  * Administrator Module (Manage Registered Accounts/Content/etc.)
  * Application Script 1 Module
  * Application Script 2 Module
  * Application Script 3 Module

I understand that to render the template you need to use the routing etc. But
how do I make it that if a certain link is called, it will called the specific
module and pull methods from there. Is it OK, to create a one main controller
for the routing and for every method in the routing I import one of the
modules above?

    
    
    @app.route('/')
      def index():
        return render_template("index.html")
    
    @app.route('/login/', methods = ('GET', 'POST'))
      def login():
        from session import login
        -> call method from 'login' here
    
    @app.route('/account/<username>', methods = ('GET', 'POST'))
      def login():
        from administrator import view_account
        -> call method from 'view_account' here
    

is this a good practice? or should I just start at the header and import every
module I have in this package. My first thinking was to prevent that the apps
to load to long because of the size of the script, only certain module will be
called if the page that need that module is accessed or something like that.


Answer: If I got your question right, then you for sure want to use blueprints :) Read
more in [documentation](http://flask.pocoo.org/docs/blueprints/)

Basically this is the way how to make Flask application modular without one
controller with all the possible modules imported there or some other hacks.

Here you can find an [example of
application](https://github.com/mitsuhiko/flask/wiki/Large-app-how-to) which
uses blueprints.

