Skip to content

Commit

Permalink
use feature detection for jinja extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed Apr 30, 2024
1 parent 71b7f6f commit efb7706
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/flask_debugtoolbar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import annotations

import collections.abc as c
import importlib.metadata
import os
import typing as t
import urllib.parse
import warnings
from contextvars import ContextVar

import jinja2.ext
from flask import Blueprint
from flask import current_app
from flask import Flask
Expand All @@ -27,8 +27,6 @@
from .utils import gzip_compress
from .utils import gzip_decompress

_jinja_version = importlib.metadata.version("jinja2")

module: Blueprint = Blueprint("debugtoolbar", __name__)


Expand Down Expand Up @@ -66,10 +64,11 @@ def __init__(self, app: Flask | None = None) -> None:
self.debug_toolbars_var: ContextVar[dict[Request, DebugToolbar]] = ContextVar(
"debug_toolbars"
)
jinja_extensions = ["jinja2.ext.i18n"]
jinja_extensions = [jinja2.ext.i18n]

if _jinja_version[0] == "2":
jinja_extensions.append("jinja2.ext.with_")
# Jinja2<3
if hasattr(jinja2.ext, "with_"):
jinja_extensions.append(jinja2.ext.with_)

# Configure jinja for the internal templates and add url rules
# for static data
Expand Down

0 comments on commit efb7706

Please sign in to comment.