It’s only 3 routes, right? Well, we are talking about large applications in this article. Right now this doesn’t seem like a big deal. In the example above, we place all the routes in one file. The directory structure for such an application might look something like this. # Website routes def home(): return "Home" # API endpoints def api(): return "API" # Admin pages def admin_home(): return "Admin Home" if _name_ = "_main_": Here’s an example of such a structure: from flask import FlaskĪpp.om_object( 'config.DevConfig') In most cases, it’s sufficient when demonstrating other Flask features where application structure doesn’t matter too much. It’s no surprise either, it’s easy and straightforward. The beginner’s method is something commonly seen in Flask tutorials. Let’s discuss the 2 main ways to organise Flask applications. By then, you understand exactly why things should be structured the way they are. When you finally uncover the secret to structuring Flask applications properly, you would have likely made several apps with varying structures until you get to the best practices. I know this sounds crazy, but these mistakes are vital in order to develop the right habits the hard way. Of course, this means you’re prone to making some errors in your structure, but that’s a good thing. Flask gives you the keys to the kingdom and says “Do whatever you want”. I find this to be rather limiting, I like the freedom to structure my application however I want. One of the advantages is that it’s less prone to errors and bad application design. It provides a rigid structure and enforces it. Especially in comparison to a framework like Django. What do I mean by freedom? Well, Flask is extremely flexible. Freedom is power, but with great power, comes great responsibility. The most important reason is the freedom it gives me. If you read my blog, you’ll realise just how much I love it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |