-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
47 lines (36 loc) · 1.18 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from flask import Flask, render_template, request
from random import randint
from pymongo.mongo_client import MongoClient
from pymongo.server_api import ServerApi
from dotenv import load_dotenv
import os
load_dotenv()
app = Flask(__name__)
app.config['SECRET_key'] = f'{os.urandom(randint(20, 50))}'
uri = f"mongodb+srv://sas2k:{os.getenv('DBPass')}@clientbase.pk701wj.mongodb.net/?retryWrites=true&w=majority"
client = MongoClient(uri, server_api=ServerApi('1'))
clients = []
db = client.Clients
cluster = db.Data
try:
client.admin.command('ping')
print("Pinged your deployment. You successfully connected to MongoDB!")
except Exception as e:
print(e)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
data = request.form
items = {
'Name': data['UserName'],
'Email': data['UserEmail'],
'Message': data['TextBody']
}
cluster.insert_one(items)
print(cluster.find_one())
return render_template('index.html')
@app.route('/projects', methods=['GET', 'POST'])
def projects():
return render_template('projects.html')
if __name__ == '__main__':
app.run(debug=True)