Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions QR-Code-Flask-App/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# QR Code Generator (Flask)

A small web app that turns any URL into a downloadable QR code image.

## Features
- Enter a URL and generate a QR code instantly
- Automatically adds `https://` if you forget it
- Download the QR code as a PNG

## Requirements
- Python 3.8+
- Flask, qrcode, Pillow

## Installation
```bash
pip install -r requirements.txt
```

## Usage
```bash
python app.py
```
Then open http://127.0.0.1:5000 in your browser, enter a URL, and click download.

## Project Structure
```
QR-Code-Flask-App/
├── app.py
├── templates/
│ └── index.html
├── requirements.txt
└── README.md
```
59 changes: 59 additions & 0 deletions QR-Code-Flask-App/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from flask import Flask, render_template, request, send_file
import qrcode
import io

app = Flask(__name__)


@app.route("/", methods=["GET", "POST"])
def index():
qr_ready = False

if request.method == "POST":
url = request.form.get("url", "").strip()

if url:
# Add https:// if the user forgot it
if not url.startswith(("http://", "https://")):
url = "https://" + url

qr_ready = True
return render_template("index.html", qr_ready=qr_ready, url=url)

return render_template("index.html", qr_ready=qr_ready, url="")


@app.route("/download")
def download():
"""Generates the QR code image on the fly and sends it to the browser as a download."""
url = request.args.get("url", "")

if not url:
return "No URL provided", 400

qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_M,
box_size=10,
border=4,
)
qr.add_data(url)
qr.make(fit=True)

img = qr.make_image(fill_color="black", back_color="white")

# Save image to memory instead of disk, so it can be sent straight to the browser
buffer = io.BytesIO()
img.save(buffer, format="PNG")
buffer.seek(0)

return send_file(
buffer,
mimetype="image/png",
as_attachment=True,
download_name="qr.png",
)


if __name__ == "__main__":
app.run(debug=True)
2 changes: 2 additions & 0 deletions QR-Code-Flask-App/requirments.txt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask
qrcode[pil]
83 changes: 83 additions & 0 deletions QR-Code-Flask-App/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>QR Code Generator</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f7f7f8;
display: flex;
justify-content: center;
padding: 40px 16px;
}
.card {
background: white;
border: 1px solid #e2e2e2;
border-radius: 12px;
padding: 24px;
width: 100%;
max-width: 380px;
}
h1 { font-size: 1.3rem; margin: 0 0 20px; }
input[type="text"] {
width: 100%;
padding: 10px;
border-radius: 8px;
border: 1px solid #ccc;
font-size: 1rem;
box-sizing: border-box;
}
button {
margin-top: 12px;
width: 100%;
padding: 10px;
border: none;
border-radius: 8px;
background: #2563eb;
color: white;
font-size: 1rem;
cursor: pointer;
}
button:hover { background: #1d4ed8; }
.qr-box {
margin-top: 20px;
text-align: center;
}
.qr-box img {
max-width: 100%;
border: 1px solid #e2e2e2;
border-radius: 8px;
}
a.download-link {
display: block;
margin-top: 12px;
text-align: center;
background: transparent;
border: 1px solid #2563eb;
color: #2563eb;
padding: 10px;
border-radius: 8px;
text-decoration: none;
}
a.download-link:hover { background: #2563eb; color: white; }
</style>
</head>
<body>
<div class="card">
<h1>QR Code Generator</h1>
<form method="POST">
<input type="text" name="url" placeholder="https://example.com" value="{{ url }}" required>
<button type="submit">Generate QR Code</button>
</form>

{% if qr_ready %}
<div class="qr-box">
<img src="/download?url={{ url }}&preview=1" alt="QR code for {{ url }}">
<a class="download-link" href="/download?url={{ url }}">Download PNG</a>
</div>
{% endif %}
</div>
</body>
</html>
Loading