-
Notifications
You must be signed in to change notification settings - Fork 0
/
originalpy.txt
53 lines (43 loc) · 1.52 KB
/
originalpy.txt
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
# Imports
import os
import qrcode
from flask import Flask, render_template, request, send_file, redirect, url_for
from io import BytesIO
# path of index.html
template_dir = os.path.abspath('./templates')
# setting up the app
app = Flask(__name__, template_folder=template_dir)
# secret key for app
app.config['SECRET_KEY'] = 'dafqdafqdafq'
@app.route('/', methods=['GET'])
def mainPage():
return render_template('index.html')
# setting up decorators to select the web path and methods in use
@app.route('/', methods=['GET', 'POST'])
# index app structure and qr gen fun
def index():
if request.method == 'POST':
data = request.form.get('data')
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4)
qr.add_data(data)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
qr_code_io = BytesIO()
img.save(qr_code_io)
qr_code_io.seek(0)
return send_file(
qr_code_io,
mimetype="image/png",
as_attachment=True,
download_name="qrcode.png",
)
return render_template('index.html')
@app.route('/docs/', methods=['GET'])
def docs():
return render_template('docs.html')
@app.route('/github/', methods=['GET'])
# func to redirect to a external link using GitHub button on page
def gitPage():
return redirect('https://github.com/ailsonguedes/QR-Generator-/tree/main')
if __name__ == '__main__':
app.run(debug=True)