Skip to main content

Jinja2 CSRF Token Extension

This is a Jinja2 extension for generating CSRF tokens in Django templates.

Installation

Install the extension using pip:

pip install jinja2_csrf

Configuration

To use this extension, you need to configure Jinja2 as a template engine in your Django settings:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.jinja2.Jinja2',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'environment': 'path.to.your.jinja2.environment',
            'extensions': ['jinja2_csrf.CSRFTokenExtension'],
        },
    },
]

Make sure to replace 'path.to.your.jinja2.environment' with the actual path to your Jinja2 environment.

Usage

In your Jinja2 templates, you can now use the csrf_token tag to generate a CSRF token:

<form method="post">
    {% csrf_token %}
    <!-- Your form fields go here -->
    <button type="submit">Submit</button>
</form>

The csrf_token tag will generate an <input> element with the CSRF token value:

<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}">

Make sure to include the csrf_token tag within your form to protect against CSRF attacks.

Metadata

Release files for jinja2_csrf 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jinja2_csrf 1.0
File Size Uploaded Provenance
jinja2_csrf-1.0.tar.gz 3.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for jinja2_csrf 1.0
File Interpreter ABI Platform
jinja2_csrf-1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 6.4 kB

Release files / jinja2_csrf-1.0.tar.gz

Download URL jinja2_csrf-1.0.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4c3d1f4c87c808b417b9010e57ddfc7a9e40b285e6361957d3dca1e24d6071f0
BLAKE2b-256 checksum
How to use checksums
afd3474af8fff74ba26c3559ab65a725dee7f40d213e5bf07bc3d932df30c815
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release files / jinja2_csrf-1.0-py2.py3-none-any.whl

Download URL jinja2_csrf-1.0-py2.py3-none-any.whl
Size 2.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5de440dd5190b0e038e5020d84ab07981f35f00a2489854cbef22471982c177d
BLAKE2b-256 checksum
How to use checksums
0ed01aa3c4d4498491b36cca9a2b8993d27e91d399e04bdd1ede9f3193cb902d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Security for jinja2_csrf 1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page