Registry / web-framework / django-qr-code

django-qr-code

JSON →
library4.2.0pypypi✓ verified 87d ago

An application that provides tools for displaying QR codes on your Django site. It supports generation of QR codes as SVG, PNG, or Base64 embedded images, via both Django template tags and a Python API. The current version, 4.2.0, released in May 2025, actively tracks Django and Python releases, ensuring compatibility with the latest versions.

pip install django-qr-code
INSTALL
IMPORT
SIG · DJANGO-QR-CODE
D
django-qr-code
web-frameworkpythonv4.2.0
Install
5.3s avg
Import
Disk
76MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 76.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 5.3s · import 0.000s · 76MB
76MB installed
● package 76MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

load qr_code (template tag)
{% load qr_code %}
Used in Django templates to enable QR code generation tags.
QRCodeOptions
from qr_code.qrcode.utils import QRCodeOptions
For configuring QR code generation parameters programmatically.
make_qr_code_with_options
from qr_code.qrcode.utils import make_qr_code_with_options
Function to generate QR codes programmatically without caching.
get_or_make_cached_embedded_qr_code
from qr_code.qrcode.cache import get_or_make_cached_embedded_qr_code
New in 4.2.0 for caching generated embedded QR code HTML, requires Django caching backend.
include qr_code.urls
path('qr_code/', include('qr_code.urls', namespace='qr_code'))
Adds QR code generation URLs to your project's routing for template tags and API.

To quickly integrate `django-qr-code`, first add it to your `INSTALLED_APPS` and include its URL patterns in your project's `urls.py`. Then, use the `{% qr_from_text %}` template tag in any Django template to generate and display QR codes. Ensure `Pillow` is installed if generating PNG images.

# myproject/settings.py INSTALLED_APPS = [ # ... other apps 'qr_code', ] # myproject/urls.py from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('qr_code/', include('qr_code.urls', namespace='qr_code')), # Add this line # ... other paths ] # myapp/templates/myapp/my_template.html {% load qr_code %} <h1>My QR Code</h1> <p>This is a QR code for example.com:</p> {% qr_from_text "https://example.com" size="t" image_format="svg" %} <p>Or a bigger PNG with custom alt text:</p> {% qr_from_text "https://my-app.com/secret" size="m" image_format="png" alt="Secret link" %}
Debug
Known issues
breaking`django-qr-code` versions 4.1.0 and later dropped support for Python versions older than 3.10.
fix
Upgrade your Python environment to 3.10 or newer, or pin `django-qr-code` to `<4.1.0` if using an older Python version.
affects: >=4.1.0
breakingVersions 4.1.0 and later require Pydantic >= 2.7. Older Pydantic versions are no longer supported.
fix
Upgrade Pydantic: `pip install "pydantic>=2.7,<3.0"`.
affects: >=4.1.0
gotchaGenerating QR codes as PNG images (e.g., `image_format="png"`) requires the `Pillow` library to be installed.
fix
Install `Pillow` explicitly: `pip install Pillow` or install `django-qr-code` with the `pil` extra: `pip install "django-qr-code[pil]"`.
affects: All
gotchaThe `qr_code.urls` must be included in your project's `urls.py` with the correct namespace (`namespace='qr_code'`) for template tags and API views to function correctly.
fix
Add `path('qr_code/', include('qr_code.urls', namespace='qr_code'))` to your project's `urlpatterns`.
affects: All
gotchaThe `get_or_make_cached_embedded_qr_code` utility (new in 4.2.0) requires a Django caching backend to be configured and active in your `settings.py` to cache QR codes effectively.
fix
Configure a caching backend in your `settings.py`, e.g., `CACHES = {'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}`.
affects: >=4.2.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'Pillow'
Attempting to generate PNG QR codes without the Pillow library installed, which is required for image processing.
fix
Install Pillow: `pip install Pillow` or install `django-qr-code` with the `pil` extra: `pip install "django-qr-code[pil]"`.
django.urls.exceptions.NoReverseMatch: Reverse for 'qr_code_from_text' not found. 'qr_code' is not a registered namespace.
The `qr_code.urls` module is not correctly included in the project's `urls.py` or the specified namespace is incorrect.
fix
Add `path('qr_code/', include('qr_code.urls', namespace='qr_code'))` to your project's `urlpatterns`.
PydanticUserError: Pydantic 2.x requires a Pydantic 2.x compatible Pydantic-settings.
Your Pydantic version is incompatible with `django-qr-code` 4.1.0+. It requires Pydantic >= 2.7 for API view validation.
fix
Upgrade Pydantic to a compatible version: `pip install "pydantic>=2.7,<3.0"`.
Upgrade
Version history
4.2.0latest on PyPI · released May 8, 2025
Audit
Dependencies
DjangorequiredCore framework requirement, compatible with Django >= 4.2 (including 5.x).
qrcoderequiredUnderlying QR code generation library (specifically >=7.4, <8).
PillowoptionalRequired for generating QR codes as PNG images (specifically >=10.0, <11).
PydanticoptionalRequired for API view validation (specifically >=2.7, <3.0).
Agent activity
6 hits · last 30 days
node
6
Resources