{"id":9682,"library":"django-qr-code","title":"django-qr-code","description":"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.","status":"active","version":"4.2.0","language":"en","source_language":"en","source_url":"https://github.com/dprog-philippe-docourt/django-qr-code","tags":["django","qr-code","web-development","utility","image-generation"],"install":[{"cmd":"pip install django-qr-code","lang":"bash","label":"Base installation"},{"cmd":"pip install \"django-qr-code[pil]\"","lang":"bash","label":"With Pillow for PNG image support"}],"dependencies":[{"reason":"Core framework requirement, compatible with Django >= 4.2 (including 5.x).","package":"Django","optional":false},{"reason":"Underlying QR code generation library (specifically >=7.4, <8).","package":"qrcode","optional":false},{"reason":"Required for generating QR codes as PNG images (specifically >=10.0, <11).","package":"Pillow","optional":true},{"reason":"Required for API view validation (specifically >=2.7, <3.0).","package":"Pydantic","optional":true}],"imports":[{"note":"Used in Django templates to enable QR code generation tags.","symbol":"load qr_code (template tag)","correct":"{% load qr_code %}"},{"note":"For configuring QR code generation parameters programmatically.","symbol":"QRCodeOptions","correct":"from qr_code.qrcode.utils import QRCodeOptions"},{"note":"Function to generate QR codes programmatically without caching.","symbol":"make_qr_code_with_options","correct":"from qr_code.qrcode.utils import make_qr_code_with_options"},{"note":"New in 4.2.0 for caching generated embedded QR code HTML, requires Django caching backend.","symbol":"get_or_make_cached_embedded_qr_code","correct":"from qr_code.qrcode.cache import get_or_make_cached_embedded_qr_code"},{"note":"Adds QR code generation URLs to your project's routing for template tags and API.","symbol":"include qr_code.urls","correct":"path('qr_code/', include('qr_code.urls', namespace='qr_code'))"}],"quickstart":{"code":"# myproject/settings.py\nINSTALLED_APPS = [\n    # ... other apps\n    'qr_code',\n]\n\n# myproject/urls.py\nfrom django.contrib import admin\nfrom django.urls import path, include\n\nurlpatterns = [\n    path('admin/', admin.site.urls),\n    path('qr_code/', include('qr_code.urls', namespace='qr_code')), # Add this line\n    # ... other paths\n]\n\n# myapp/templates/myapp/my_template.html\n{% load qr_code %}\n\n<h1>My QR Code</h1>\n<p>This is a QR code for example.com:</p>\n{% qr_from_text \"https://example.com\" size=\"t\" image_format=\"svg\" %}\n\n<p>Or a bigger PNG with custom alt text:</p>\n{% qr_from_text \"https://my-app.com/secret\" size=\"m\" image_format=\"png\" alt=\"Secret link\" %}","lang":"python","description":"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."},"warnings":[{"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.","message":"`django-qr-code` versions 4.1.0 and later dropped support for Python versions older than 3.10.","severity":"breaking","affected_versions":">=4.1.0"},{"fix":"Upgrade Pydantic: `pip install \"pydantic>=2.7,<3.0\"`.","message":"Versions 4.1.0 and later require Pydantic >= 2.7. Older Pydantic versions are no longer supported.","severity":"breaking","affected_versions":">=4.1.0"},{"fix":"Install `Pillow` explicitly: `pip install Pillow` or install `django-qr-code` with the `pil` extra: `pip install \"django-qr-code[pil]\"`.","message":"Generating QR codes as PNG images (e.g., `image_format=\"png\"`) requires the `Pillow` library to be installed.","severity":"gotcha","affected_versions":"All"},{"fix":"Add `path('qr_code/', include('qr_code.urls', namespace='qr_code'))` to your project's `urlpatterns`.","message":"The `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.","severity":"gotcha","affected_versions":"All"},{"fix":"Configure a caching backend in your `settings.py`, e.g., `CACHES = {'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}}`.","message":"The `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.","severity":"gotcha","affected_versions":">=4.2.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Install Pillow: `pip install Pillow` or install `django-qr-code` with the `pil` extra: `pip install \"django-qr-code[pil]\"`.","cause":"Attempting to generate PNG QR codes without the Pillow library installed, which is required for image processing.","error":"ModuleNotFoundError: No module named 'Pillow'"},{"fix":"Add `path('qr_code/', include('qr_code.urls', namespace='qr_code'))` to your project's `urlpatterns`.","cause":"The `qr_code.urls` module is not correctly included in the project's `urls.py` or the specified namespace is incorrect.","error":"django.urls.exceptions.NoReverseMatch: Reverse for 'qr_code_from_text' not found. 'qr_code' is not a registered namespace."},{"fix":"Upgrade Pydantic to a compatible version: `pip install \"pydantic>=2.7,<3.0\"`.","cause":"Your Pydantic version is incompatible with `django-qr-code` 4.1.0+. It requires Pydantic >= 2.7 for API view validation.","error":"PydanticUserError: Pydantic 2.x requires a Pydantic 2.x compatible Pydantic-settings."}]}