Posts

Showing posts from April 14, 2019

Python -Flask I want to display the data that present in Mongodb on a html page in clean format

Image
0 2 I have a list of questions data in Mongodb database. I want to display question by question on html page. This is my Flask code from flask import Flask, render_template, request, url_for from pymongo import MongoClient from bson.json_util import dumps import json client = MongoClient('localhost:27017') db = client.girish app = Flask(__name__) @app.route("/questions", methods = ['GET']) def questions(): try: names = db.questions.find({},{"ques":1,"options":1,"_id":0,"quesid":1,"ans":1}).limit(10) return render_template('index.html', names=names) #return dumps(names) except Exception as e: return dumps({'error' : str(e)}) @app.route("/answers", methods =