summaryrefslogtreecommitdiff
path: root/django/template/base.py
AgeCommit message (Collapse)Author
2026-04-28Fixed #35738 -- Deprecated double-dot variable lookups.David Smith
2026-02-10Fixed #36903 -- Fixed further NameErrors when inspecting functions with ↵93578237
deferred annotations. Provide a wrapper for safe introspection of user functions on Python 3.14+. Follow-up to 601914722956cc41f1f2c53972d669ddee6ffc04.
2025-12-01Fixed #36712 -- Evaluated type annotations lazily in template tag registration.Jacob Walls
Ideally, this will be reverted when an upstream solution is available for https://github.com/python/cpython/issues/141560. Thanks Patrick Rauscher for the report and Augusto Pontes for the first iteration and test.
2025-09-12Refs #35667 -- Cached Django file prefixes for warnings.Adam Johnson
2025-09-04Refs #36559, #35667 -- Used skip_file_prefixes in PartialTemplate.source ↵farhan
warning.
2025-09-03Fixed #36559 -- Respected verbatim and comment blocks in PartialTemplate.source.farhan
2025-09-03Refs #36559 -- Ran template partial source tests in debug mode only.farhan
Added a warning for accessing PartialTemplate.source when debugging is disabled. Thanks Sarah Boyce for the idea.
2025-08-14Fixed #36410 -- Added support for Template Partials to the Django Template ↵farhan
Language. Introduced `{% partialdef %}` and `{% partial %}` template tags to define and render reusable named fragments within a template file. Partials can also be accessed using the `template_name#partial_name` syntax via `get_template()`, `render()`, `{% include %}`, and other template-loading tools. Adjusted `get_template()` behavior to support partial resolution, with appropriate error handling for invalid names and edge cases. Introduced `PartialTemplate` to encapsulate partial rendering behavior. Includes tests and internal refactors to support partial context binding, exception reporting, and tag validation. Co-authored-by: Carlton Gibson <carlton@noumenal.es> Co-authored-by: Natalia <124304+nessita@users.noreply.github.com> Co-authored-by: Nick Pope <nick@nickpope.me.uk>
2025-07-23Refs #36500 -- Rewrapped long docstrings and block comments via a script.django-bot
Rewrapped long docstrings and block comments to 79 characters + newline using script from https://github.com/medmunds/autofix-w505.
2025-06-18Fixed #36465, Refs #35816 -- Disallowed '+' and '-' characters in template ↵haileyajohnson
variable names. Regression in 5183f7c287a9a5d61ca1103b55166cda52d9c647. Thank you to Jon Banafato and Baptiste Mispelon for the report.
2025-04-17Fixed #28050 -- Added template name to TemplateSyntaxError.farhan
2025-03-11Fixed #35816 -- Handled parsing of scientific notation in DTL. (#19213)haileyajohnson
* Refs #35816 -- Improved test coverage of FilterExpression. * Fixed #35816 -- Made FilterExpression parse scientific numbers. --------- Co-authored-by: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com>
2024-11-28Fixed #35897 -- Removed unnecessary escaping in template's get_exception_info().Klaas van Schelven
2024-10-10Fixed #35789 -- Improved the error message raised when the tag must be first ↵ekinertac
in the template.
2024-09-17Fixed #35735 -- Enabled template access to methods and properties of classes ↵Fabian Braun
with __class_get_item__.
2023-10-02Fixed #34883 -- Allowed template tags to set extra data on templates.Carlton Gibson
By setting a value in the `parser.extra_data` mapping, template tags pass additional data out of the parsing context. Any extra data set is exposed on the template via the matching `.extra_data` attribute. Library authors should use a key to namespace extra data. The 'django' namespace is reserved for internal use.
2023-08-02Removed unneeded escapes in regexes.Mariusz Felisiak
Special characters lose their special meaning inside sets of characters. "-" lose its special meaning if it's placed as the first or last character. Follow up to 7c6b66383da5f9a67142334cd2ed2d769739e8f1.
2023-05-18Avoided parallel assignment in template classes.Adam Johnson
2023-02-08Refs #7430 -- Removed broken Template.__iter__().Anders Hovmöller
Co-authored-by: Anders Hovmöller <anders.hovmoller@dryft.se>
2022-05-20Fixed #33653 -- Fixed template crash when calling methods for built-in types ↵cheng
without required arguments. Regression in 09341856ed9008875c1cc883dc0c287670131458.
2022-02-16Removed unused Node.__iter__().Keryn Knight
2022-02-07Refs #33476 -- Reformatted code with Black.django-bot
2022-02-03Refs #33476 -- Refactored problematic code before reformatting by Black.Mariusz Felisiak
In these cases Black produces unexpected results, e.g. def make_random_password( self, length=10, allowed_chars='abcdefghjkmnpqrstuvwxyz' 'ABCDEFGHJKLMNPQRSTUVWXYZ' '23456789', ): or cursor.execute(""" SELECT ... """, [table name], )
2022-02-02Fixed #33474 -- Added __slots__ to Variable and FilterExpression.Keryn Knight
2022-01-07Avoided isinstance(…, Variable) calls in FilterExpression.resolve().Keryn Knight
By determining the variable type within __init__() instead of resolve() we can skip an isinstance() check at template runtime. Templates are executed in production more often than the parse trees themselves, assuming the cached Loader is used.
2021-08-25Refs #32919 -- Simplified Lexer.create_token() by reorganizing blocks.Chris Jerdonek
2021-08-25Refs #32919 -- Added assertion for token start in Lexer.create_token().Chris Jerdonek
This adds an assertion in the code path where the method would otherwise return None, which isn't allowed.
2021-08-09Fixed #33002 -- Made DebugLexer.tokenize() more closely parallel ↵Chris Jerdonek
Lexer.tokenize().
2021-08-09Refs #33002 -- Renamed variable from bit to token_string in Lexer.tokenize().Chris Jerdonek
2021-08-09Refs #33002 -- Optimized Lexer.tokenize() by skipping computing lineno when ↵Chris Jerdonek
not needed.
2021-08-09Fixed #32990 -- Simplified and optimized tag regex.Greg Twohig
Thanks Chris Jerdonek for the review.
2021-08-05Refs #32986 -- Moved TRANSLATOR_COMMENT_MARK to ↵Chris Jerdonek
django.utils.translation.template.
2021-08-05Fixed #32986 -- Removed unneeded str.find() call in Lexer.create_token().Chris Jerdonek
Unnecessary since 47ddd6a4082d55d8856b7e6beac553485dd627f7.
2021-08-02Fixed #32919 -- Optimized lexing & parsing of templates.Keryn Knight
This optimizes: - Lexer.create_token() by avoiding startswith() calls, - Parser.parse() by re-using the token type enum's value, - Parser.extend_nodelist() by removing unnecessary isinstance() check, - some Node subclasses by removing the implicit "nodelist" from "child_nodelists", - Variable.__init__() by avoiding startswith() calls.
2021-07-02Fixed #28935 -- Fixed display of errors in extended blocks.cammil
Get the template that caused the exception and get the exception info from that template, using the node that caused the exception.
2021-06-11Fixed #32824 -- Improved performance of NodeList.render().Keryn Knight
This avoids the following: - checking that each item in the nodelist is a subclass of Node, - calling str() on the render_annotated() output, because it's documented that Node.render() must return a string, - calling mark_safe() on the output, when the value to be wrapped is definitively known to be a string because the result of ''.join() is always of that type, - using an intermediate list to store each individual string.
2021-06-07Fixed #32814 -- Improved performance of TextNode.Keryn Knight
This avoids calling render() and handling exceptions, which is not necessary for text nodes.
2021-03-17Refs #24121 -- Added __repr__() to Origin and Template.Tiago Honorato
2021-02-26Refs #24121 -- Added __repr__() to FilterExpression, Lexer, Parser, and Token.David Smith
2020-05-11Refs #30116 -- Simplified regex match group access with Match.__getitem__().Jon Dufresne
The method has been available since Python 3.6. The shorter syntax is also marginally faster.
2019-12-10Used Signature API instead of deprecated inspect.getcallargs().Baptiste Mispelon
inspect.getcallargs() was deprecated in Python 3.5 and the Signature API (PEP 362) has better support for decorated functions (by default, it follows the __wrapped__ attribute set by functools.wraps for example).
2019-12-10Used full module import for inspect in template/base.py.Baptiste Mispelon
2019-10-29Fixed #30899 -- Lazily compiled import time regular expressions.Hasan Ramezani
2019-10-09Improved performance of django.template.base.Parser.Alex Gaynor
pop(0), which is used to fetch each token, is O(n) in the length of the list. By reversing the list and operating off the end, we can perform next_token(), prepend_token(), and delete_first_token() in constant time.
2019-10-02Fixed some typos in comments and docs.Min ho Kim
Thanks to Mads Jenson for review.
2019-09-24Removed some outdated backwards compatibility imports and misleading comments.Mads Jensen
EmptyResultSet moved in 46509cf13dbf049f75077981c29ef2c60b5a96ab. FieldDoesNotExist moved in 8958170755b37ce346ae5257c1000bd936faa3b0. BoundField and pretty_name moved in 8550161e531a603d57723850fb09c4c9b7ca60b9. EMPTY_VALUES moved in 471596fc1afcb9c6258d317c619eaf5fd394e797. BaseRunserverCommand moved in 5c53e30607014163872e89c221b206992a9acfef.
2019-05-07Removed unnecessary line in DebugLexer.tokenize().sanchjat
2018-08-01Fixed typos in comments and docs.luz.paz
2018-07-31Fixed #29617 -- Fixed Template crash if template_string is lazy.Dražen Odobašić
Regression in 3a148f958dddd97c1379081118c30fbede6b6bc4.
2018-05-25Fixed #29400 -- Fixed crash in custom template filters that use decorated ↵Ryan Rubin
functions. Regression in 620e9dd31a2146d70de740f96a8cb9a6db054fc7.