This is the article to let you display the concept of database connectivity using FLask and PyMongo. PyMongo Basically a Python library. MongoDB is non-realational database. As per prequsite you may want to look at following articles before beginning with this article.
1. Setting Up and Running Python Flask Project
2. Introduction to Python Flask and Jinja2
I will create single pages web application using flask and PyMongo. I won't be using any templating here, rather use request to insert and view data. I have provide enough content and description so you can follow along.
Download Mongo DB
You can download MongoDB from official site of MongoDB. If you just want to quickly go to page follow https://www.mongodb.com/download-center?jmp=nav#community
Starting MongoDB Server
Following code will be valid for linux versions in particular. Please look at setup and running guide to run MongoDB in different versions
$ sudo service mongod start # for linux versions
Installing all required packages
Once you have mongod in place, we need Flask and PyMongo to connect with mongo database
$ pip install flask $ pip install pymongo
If you need more installation guide please follow following link https://api.mongodb.com/python/current/installation.html
Writing code
The main concept of this tutorial is to get you through quick feel of Flask and Mongo Database. I could have created views get template in place but this approach will help to grab quick knowledge to play with data.
If you like to view GitHub version of code Click Here
OR
Create any filename similar to app.py which we will use to run later
Description/Conculusion
In above program there are various functions to carry insert, read and delete. For update your data you can use update() function.
Comments