Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask/Bottle project organization

Tags:

python

flask

I've been looking into microframeworks for Python, and have come across two interesting options, Flask and Bottle. each have some similar features. One thing I noticed is that all the example sites show all the application code located inside a single Python file. Obviously, for even moderately sized sites, this would become difficult to manage quite quickly. Do either (or both) of these frameworks support being broken up among different files, and if so how would that be accomplished?

I'm familiar with Django, and like how its a little more structured, but i would rather use something more lightweight, but still powerful.

like image 843
Jason Miesionczek Avatar asked Mar 21 '11 17:03

Jason Miesionczek


1 Answers

I don't have any experience with Bottle, but take a look at the Flask docs on larger applications. My Flask apps all use multiple Flask Module objects as that page recommends, one per Python module, and it seems to work just fine.

One thing that's nice about the Module objects is that you can customize dispatch on each one to create URL routing "domains" in your app. So for example, I'm trying to ape a Windows app in some of my code so I have a CaseInsensitiveModule that does case-insensitive dispatch, and I rigged up a RemoteModule to turn HTTP requests into Python methods using the Flask/Werkzeug routing system.

(Note that in current Flask versions, Modules are now Blueprints.)

like image 139
Nicholas Riley Avatar answered Oct 03 '22 07:10

Nicholas Riley