开发者

Flask/Bottle project organization

I've 开发者_Python百科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.


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.)


I can't see how there could be any way of stopping this from working. Flask and Bottle, like Django, are just Python underneath, and Python allows you to break up files into modules. As long as you importing the relevant functions into the main script, they will just work exactly as if they were defined there.


I know a few people have started using my own article on doing this with Flask, although there are obviously other ways to do it depending on the size of the project; even I drop the directory type module for a file based one for smaller projects. Have a look at http://www.cols-code-snippets.co.uk/2011/02/my-take-on-flask-application-skeleton.html


I recently posted a sort of tutorial on how to get started with Bottle+Jinja2 in Google App Engine. My emphasis here is on how to organize the project files. You may be able to get something that you can use: http://codeaspoetry.wordpress.com/2011/11/27/how-to-build-a-web-app-using-bottle-with-jinja2-in-google-app-engine/


It really depends what you are trying to achieve, for micro service/applications/websites bottle is very straight forward and light weight. If you plan your application to grow by the time then Flask might be good option for you coz it has lot of extensions. We have about 40 to 50 micro services written in bottle and never faced any issues.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜