Code Monkey home page Code Monkey logo

flask_starter's Introduction

Flast Starter App

This is a basic example that shows how to setup a flask application

Here's the basic directory structure;

├── app
│   ├── config.py
│   ├── __init__.py
│   ├── models
│   │   └── __init__.py
│   ├── resources
│   │   └── __init__.py
│   ├── templates
│   │   └── index.html
│   ├── utils
│   │   └── __init__.py
│   └── views
│       └── __init__.py
├── README.md
├── requirements.txt
├── test
│   └── __init__.py
└── wsgi.py

models - This holds all your data classes and utility functions that interact with any kind of persitence (Mongo, Mysql etc)

resources - This package usually holds endpoints related to an API. Try to avoid putting view endpoints here. Put them in the view package instead

view - This package holds any endpoint that deals with any visual representation i.e endpoints that return html

templates - Put all your .html files here

utils - Put utility functions here. Mostly reusable logic used in the view and resources

config.py - All app your configuration goes here. Remember to put the right config in the right class. Anything reusable should go in Config

This is not a strict life or death way of structuring a flask app. Remember programming is art. As long as your app can be testable go with whatever makes you sleep at night 😌

Tips (Frequent updates expected):

  1. For any file in the models package. Make sure it's within a class or method/function. It makes it easy to mock stuff during testing
  2. While organizing your models be careful while using the orgranize imports feature available in text editors and IDEs it can affect how your models are loaded(i.e relationships) thus prevent your app from starting.
  3. While testing your endpoints start with negative vibes first. Basically, start testing for non 200/201 responses first
  4. Any method/function/class in the utils package should not depend on anything outside the utils package (Scope of your code. They can depend on libraries).
  5. Make use of Flask extensions. They save a lot of time! Here is a good place to start. should be passed in as parameters. It helps prevent cyclic dependencies

Further References:

flask_starter's People

Contributors

michaelbukachi avatar

Watchers

James Cloos avatar  avatar

Forkers

dr-aryone

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.