Giter Club home page Giter Club logo

flask-mongodb-boilerplate's Introduction

flask-mongodb-boilerplate

A boilerplate using flask and mongodb

Prerequisites

  1. Understanding of flask, uWSGI
  2. Understanding of docker
  3. Understanding of mongodb
  4. Understanding of flask-mongoengine (A document mapper library)

Local setup instruction

  1. install and start docker
  2. clone this repo
  3. goto root directory of repo
  4. run this > docker-compose up

this will create two container >

  1. app container flask-mongodb-boilerplate_web_1

  2. mongodb container flask-mongodb-boilerplate_mongo_1

If you check the docker-compose file you will see, that I have mentioned MONGO_INITDB_ROOT_USERNAME, MONGO_INITDB_ROOT_PASSWORD. So this is a username and password for admin(default) database. Now you have to create a new database for your application. For example in this boilerplate I am using sample database. Now follow these steps to create user for sample database(ex.sample)(You have to do this only once)

  1. docker exec -it flask-mongodb-boilerplate_mongo_1 bash (Goto mongo container shell)
  2. mongo (open mongo shell)
  3. use admin (switch to admin database, need authentication to create new db)
  4. db.auth(username, password); > use username and password that you have mentioned in docker-compose file
  5. use sample (now switch to new database> sample)
  6. db.createUser( { user: "username for sample db", pwd: 'password for sample db'(), roles: [ "readWrite", "dbAdmin" ] } ) Use this command to create user for you sample db

Now update app/settings/configs.py file and update MONGODB_SETTINGS with your new db, username and password

Now you can access api http://localhost:5000/

Sample link - http://localhost:5000/api/sample/health/

TESTING

Write your test cases then run

pytest tests/ --capture=tee-sys

For production you just need to update configs.py file settings

Useful links

http://docs.mongoengine.org/guide/defining-documents.html

https://docs.mongodb.com/manual/mongo/

TODO's

  1. Add TESTING ENV and sample TESTING
  2. Add Documentation link about boilerplate structure

flask-mongodb-boilerplate's People

Contributors

manofsteel-ab avatar

Stargazers

 avatar

Watchers

 avatar

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.