We are ready to run our sample application.
In addition, we must add emoji.css, emoji.js, style.css and files in the static\assets folder. We must add the below three HTML files in the templates folder ( index.html, searchlist.html and update.html).Īll these three files used the features of jinja2 framework to render the model values from app.py. Return render_template( ' searchlist.html',todos=todos_l,t=title,h=heading) Todos = db.todo # Select the collection name def redirect_url():Ī1= " active" return render_template( ' " " /uncompleted")Ī2= " active" return render_template( ' " /completed")Ī3= " active" return render_template( ' " /done") Heading = " TODO Reminder with Flask and MongoDB"Ĭlient = MongoClient( " mongodb://127.0.0.1:27017") # host uriĭb = client.mymongodb # Select the database Title = " TODO sample application with Flask and MongoDB"
#Simple mongodb python example code#
PIP is the abbreviation for python package index which is used for installing, upgrading or removing the additional python libraries from our system.Ĭopy Code from flask import Flask, render_template,request,redirect,url_for # For flask implementation from bson import ObjectId # For ObjectId to work from pymongo import MongoClient Now you can check the python and PIP version in command prompt. We installed the python 3.7 version, so it added as Python 37-32.Īlso note that Python37-32\Scripts folder is used for handling additional packages needed for python. Please select the Python to environment variables.Īfter successful installation, if you check the system environment variable, you can see the below two entries are added in the system. If needed, you can modify the installation path. Here C:mongo-data folder is used for saving mongodb files. Before running the MongoDB instance, we must create a data folder and run below command in command prompt. It will add one entry in environment variable. After successful installation it is all set to run MongoDB instance. Please click Add Python 3.7 to PATH option.
If you choose default installation, please set these variables manually.
You can select the Customize installation for adding python environment variables. It is very easy to work with flask as well as mongodb. We are going to create a sample python web application using Flask framework and MongoDB. We use Flask framework to build REST APIs and also use Pymongo to connect flask with MongoDB. In this article, we are going to create a simple Python Flask application with MongoDB as database.