-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
32 lines (25 loc) · 958 Bytes
/
Copy pathapp.py
File metadata and controls
32 lines (25 loc) · 958 Bytes
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
from flask import Flask, render_template, request, send_file
import barcode
from barcode.writer import ImageWriter
from io import BytesIO
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
barcode_value = request.form['barcode_value']
barcode_type = 'code128'
# Generar el código de barras
bar = barcode.get(barcode_type, barcode_value, writer=ImageWriter())
file_obj = BytesIO()
bar.write(file_obj)
# Retrocede el puntero al inicio del archivo para que se lea desde el comienzo
file_obj.seek(0)
return send_file(
file_obj,
mimetype='image/png',
as_attachment=True,
download_name=f'{barcode_value}.png' # Cambiado a download_name
)
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True, port=5000)