×

Construct QR Code Generator with Python and Flask

Construct QR Code Generator with Python and Flask

Construct QR Code Generator with Python and Flask


In our earlier Python Porject instructional, now we have defined to increase School Management System with Python, Flask and MySQL. On this instructional, we will be able to give an explanation for find out how to construct QR Code Generator with Python and Flask.

This present day, QR code is grow to be part of our lifestyles. All of us use QR code for a couple of functions like making bills, activating gives, obtain apps, ebook tickets and so forth.

As programmer, have you ever ever attempted to generate QR codes? It’s in point of fact quite simple. You’ll be able to simply increase mission to generate QR Code as in line with your want. On this, we will be able to increase a mission the usage of Python and Flask to create QR code.

So let’s continue with growing mission:

1. Create Mission and Set up Module

We can create mission listing qrcde-python-flask and set up all required modules.

  • Flask: This can be a micro framework from Python to create internet utility. So we will be able to set up this module to create internet packages. We can set up it the usage of the under command:

pip set up Flask
  • qrcode: We can set up qrcode Python module to generate QA code. We can set up it the usage of the under command:

pip set up qrcode

2. Create Flask Utility

We can create app.py and import required modules. We come with put in flask module and it’s strategies. We can additionally import primary module and it’s way generateCode. Then we will be able to create our flask app.


from flask import Flask, render_template, request, redirect, url_for
from primary import generateCode

app = Flask(__name__)

We create direction and test psot strategies. We can create serve as index() and enforce capability to name serve as generateCode() to get QR code by means of passing code textual content. We can render the template index.html and show generated QR code.


@app.direction('/', strategies=['GET', 'POST'])
def index():    
    generatedCode=""
    mesage=""
    if request.way == 'POST':        
        codeText = str(request.shape['codeText'])
        if codeText:
            generatedCode = generateCode(codeText)
        else:
            mesage="Please input textual content to generate code"
    go back render_template('index.html', mesage = mesage, generatedCode = generatedCode)

if __name__ == '__main__':
    app.run()

3. Enforce QR Code Generator Serve as

We can create primary.py and import qrcode module. We can create serve as generateCode() and enforce capability to generate QR code the usage of qrcode module.


import qrcode
from io import BytesIO
import base64
 
def generateCode(textual content: str, img_name: str="QRCode.png") -> any:
    code = qrcode.QRCode(
        model=1, 
        box_size=10,
        border=4
    )
    code.add_data(textual content)
    code.make(have compatibility=True)
    img = code.make_image(fill_color="black", back_color="white")
    buffer = BytesIO()
    img.save(buffer, layout="PNG")    
    qrCode = f"information:symbol/png;base64,{base64.b64encode(buffer.getvalue()).decode()}"
    go back qrCode

4. Create Template Record

We can create template report index.html and create FORM HTML to create QA code. We can additionally show generated QR code.



{% if generatedCode %}

You'll be able to obtain the picture by means of clicking on it.

qr code
{% endif %}
{% endblock %}

You’ll be able to obtain all the supply code of mission from the Obtain hyperlink under.

Download



Source link

send message
Hello,
Iam Guest Posting Services
I Have 400 sites
Status : Indexed All
Good DA : 40-60
Different Niche | Category
Drip Feed Allowed
I can instant publish
ASAP


My Services :

1. I will do your orders maximum of 1x24 hours, if at the time I'm online, I will do a maximum of 1 hour and the process is
completed.
2. If any of your orders are not completed a maximum of 1x24 hours, you do not have to pay me, or free.
3. For the weekend, I usually online, that weekend when I'm not online, it means I'm working Monday.
4. For the payment, maximum payed one day after published live link.
5. Payment via PayPal account.

If you interesting, please reply

Thank You

Regards,

iwan