Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
54 lines (41 loc) · 1.48 KB
/
Copy pathapp.py
File metadata and controls
54 lines (41 loc) · 1.48 KB
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
48
49
50
51
52
53
54
from flask import Flask,render_template ,request ,send_file
import qrcode as qr
import pymongo
app = Flask(__name__)
client =pymongo.MongoClient("mongodb+srv://prashantwadhave5:Prash2002@cluster0.wkfocs3.mongodb.net/?retryWrites=true&w=majority")
db = client.test
db = client.DYNAMIC_QR_GENERATOR # Use your actual database name
collection = db['contact_list']
@app.route('/submit_contact_form', methods=['POST'])
def submit_contact_form():
if request.method == 'POST':
name = request.form.get('name')
email = request.form.get('email')
message = request.form.get('message')
print(f"Name: {name}, Email: {email}, Message: {message}")
# Store the form data in MongoDB
collection.insert_one({
'name': name,
'email': email,
'message': message
})
return render_template('formsub.html')
else:
return "Method Not Allowed", 405
@app.route('/')
def index():
return render_template('index.html')
@app.route('/generate_qr', methods=['POST'])
def generate_qr():
url = request.form.get('url')
if not url:
return "Please enter a URL"
# Genrate QR code
img = qr.make(url)
img.save("./static/qrcode.png")
# return send_file("static/qrcode.png" ,as_attachment=True),
return render_template('qr_gen.html')
# Disable caching for development
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
if __name__ == ('__main__'):
app.run(host='0.0.0.0',port=5000)