Skip to content

Commit

Permalink
Set up db connection in app
Browse files Browse the repository at this point in the history
  • Loading branch information
shriyakalakata committed Feb 23, 2024
1 parent a050820 commit 2ad4976
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from flask import Flask, render_template, request, redirect, abort, url_for, make_response
from dotenv import load_dotenv
import os
import pymongo
from pymongo import MongoClient

load_dotenv()

app = Flask(__name__)

uri = os.getenv("MONGO_URI")
db_name = os.getenv("MONGO_DBNAME")

# Create a new client and connect to the server
client = MongoClient(uri)
db = client[db_name]

# Send a ping to confirm a successful connection
try:
client.admin.command('ping')
print("Connected to MongoDB!")
except Exception as e:
print("MongoDB connection error:", e)

0 comments on commit 2ad4976

Please sign in to comment.