use Jinja name consistently
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 38b4c1e · Browse files · 9 files·+31 added−31 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+31 added−31 removed
- other:+31 added−31 removed
Provenance
- Commit
d8259eb- Tree
8896161- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
38b4c1e
9 files changed+31 added−31 removed
modified:docs/patterns/streaming.rst+1 added-1 removed
27 unmodified lines28 29 Streaming from Templates30 ------------------------31 32-The Jinja2 template engine supports rendering a template piece by32+The Jinja template engine supports rendering a template piece by33 piece, returning an iterator of strings. Flask provides the34 :func:`~flask.stream_template` and :func:`~flask.stream_template_string`35 functions to make this easier to use.36 49 unmodified linesmodified:docs/patterns/wtforms.rst+1 added-1 removed
97 unmodified lines98 WTForm's field function, which renders the field for us. The keyword99 arguments will be inserted as HTML attributes. So, for example, you can100 call ``render_field(form.username, class='username')`` to add a class to101 the input element. Note that WTForms returns standard Python strings,102-so we have to tell Jinja2 that this data is already HTML-escaped with102+so we have to tell Jinja that this data is already HTML-escaped with103 the ``|safe`` filter.104 105 Here is the :file:`register.html` template for the function we used above, which106 takes advantage of the :file:`_formhelpers.html` template:20 unmodified linesmodified:docs/design.rst+8 added-8 removed
94 unmodified lines95 96 One Template Engine97 -------------------98 99-Flask decides on one template engine: Jinja2. Why doesn't Flask have a99+Flask decides on one template engine: Jinja. Why doesn't Flask have a100 pluggable template engine interface? You can obviously use a different101-template engine, but Flask will still configure Jinja2 for you. While102-that limitation that Jinja2 is *always* configured will probably go away,101+template engine, but Flask will still configure Jinja for you. While102+that limitation that Jinja is *always* configured will probably go away,103 the decision to bundle one template engine and use that will not.104 105 Template engines are like programming languages and each of those engines106 has a certain understanding about how things work. On the surface they107 all work the same: you tell the engine to evaluate a template with a set108 of variables and take the return value as string.109 110-But that's about where similarities end. Jinja2 for example has an110+But that's about where similarities end. Jinja for example has an111 extensive filter system, a certain way to do template inheritance,112 support for reusable blocks (macros) that can be used from inside113 templates and also from Python code, supports iterative template114 rendering, configurable syntax and more. On the other hand an engine2 unmodified lines117 other hand treats templates similar to Python modules.118 119 When it comes to connecting a template engine with an application or120 framework there is more than just rendering templates. For instance,121-Flask uses Jinja2's extensive autoescaping support. Also it provides122-ways to access macros from Jinja2 templates.121+Flask uses Jinja's extensive autoescaping support. Also it provides122+ways to access macros from Jinja templates.123 124 A template abstraction layer that would not take the unique features of125 the template engines away is a science on its own and a too large126 undertaking for a microframework like Flask.22 unmodified lines149 authentication technologies, and more. Flask may be "micro", but it's ready for150 production use on a variety of needs.151 152 Why does Flask call itself a microframework and yet it depends on two153-libraries (namely Werkzeug and Jinja2). Why shouldn't it? If we look153+libraries (namely Werkzeug and Jinja). Why shouldn't it? If we look154 over to the Ruby side of web development there we have a protocol very155 similar to WSGI. Just that it's called Rack there, but besides that it156 looks very much like a WSGI rendition for Ruby. But nearly all157 applications in Ruby land do not work with Rack directly, but on top of a49 unmodified lines207 --------------------------------208 209 Flask will never have a database layer. It will not have a form library210 or anything else in that direction. Flask itself just bridges to Werkzeug211-to implement a proper WSGI application and to Jinja2 to handle templating.211+to implement a proper WSGI application and to Jinja to handle templating.212 It also binds to a few common standard library packages such as logging.213 Everything else is up for extensions.214 215 Why is this the case? Because people have different preferences and13 unmodified linesmodified:docs/quickstart.rst+3 added-3 removed
350 unmodified lines351 -------------------352 353 Generating HTML from within Python is not fun, and actually pretty354 cumbersome because you have to do the HTML escaping on your own to keep355-the application secure. Because of that Flask configures the `Jinja2355+the application secure. Because of that Flask configures the `Jinja356 <https://palletsprojects.com/p/jinja/>`_ template engine for you automatically.357 358 Templates can be used to generate any type of text file. For web applications, you'll359 primarily be generating HTML pages, but you can also generate markdown, plain text for31 unmodified lines391 /__init__.py392 /templates393 /hello.html394 395-For templates you can use the full power of Jinja2 templates. Head over396-to the official `Jinja2 Template Documentation395+For templates you can use the full power of Jinja templates. Head over396+to the official `Jinja Template Documentation397 <https://jinja.palletsprojects.com/templates/>`_ for more information.398 399 Here is an example template:400 505 unmodified linesmodified:docs/templating.rst+11 added-11 removed
1 Templates2 =========3 4-Flask leverages Jinja2 as its template engine. You are obviously free to use5-a different template engine, but you still have to install Jinja2 to run4+Flask leverages Jinja as its template engine. You are obviously free to use5+a different template engine, but you still have to install Jinja to run6 Flask itself. This requirement is necessary to enable rich extensions.7-An extension can depend on Jinja2 being present.7+An extension can depend on Jinja being present.8 9-This section only gives a very quick introduction into how Jinja29+This section only gives a very quick introduction into how Jinja10 is integrated into Flask. If you want information on the template11-engine's syntax itself, head over to the official `Jinja2 Template11+engine's syntax itself, head over to the official `Jinja Template12 Documentation <https://jinja.palletsprojects.com/templates/>`_ for13 more information.14 15 Jinja Setup16 -----------17 18-Unless customized, Jinja2 is configured by Flask as follows:18+Unless customized, Jinja is configured by Flask as follows:19 20 - autoescaping is enabled for all templates ending in ``.html``,21 ``.htm``, ``.xml``, ``.xhtml``, as well as ``.svg`` when using22 :func:`~flask.templating.render_template`.1 unmodified line24 :func:`~flask.templating.render_template_string`.25 - a template has the ability to opt in/out autoescaping with the26 ``{% autoescape %}`` tag.27 - Flask inserts a couple of global functions and helpers into the28- Jinja2 context, additionally to the values that are present by28+ Jinja context, additionally to the values that are present by29 default.30 31 Standard Context32 ----------------33 34-The following global variables are available within Jinja2 templates34+The following global variables are available within Jinja templates35 by default:36 37 .. data:: config38 :noindex:100 unmodified lines139 140 Registering Filters141 -------------------142 143-If you want to register your own filters in Jinja2 you have two ways to do143+If you want to register your own filters in Jinja you have two ways to do144 that. You can either put them by hand into the145 :attr:`~flask.Flask.jinja_env` of the application or use the146 :meth:`~flask.Flask.template_filter` decorator.147 8 unmodified lines156 app.jinja_env.filters['reverse'] = reverse_filter157 158 In case of the decorator the argument is optional if you want to use the159 function name as name of the filter. Once registered, you can use the filter160-in your templates in the same way as Jinja2's builtin filters, for example if160+in your templates in the same way as Jinja's builtin filters, for example if161 you have a Python list in context called `mylist`::162 163 {% for x in mylist | reverse %}164 {% endfor %}45 unmodified lines210 strings. This can be used for streaming HTML in chunks to speed up211 initial page load, or to save memory when rendering a very large212 template.213 214-The Jinja2 template engine supports rendering a template piece214+The Jinja template engine supports rendering a template piece215 by piece, returning an iterator of strings. Flask provides the216 :func:`~flask.stream_template` and :func:`~flask.stream_template_string`217 functions to make this easier to use.218 11 unmodified linesmodified:docs/web-security.rst+3 added-3 removed
49 unmodified lines50 tags. For more information on that have a look at the Wikipedia article51 on `Cross-Site Scripting52 <https://en.wikipedia.org/wiki/Cross-site_scripting>`_.53 54-Flask configures Jinja2 to automatically escape all values unless54+Flask configures Jinja to automatically escape all values unless55 explicitly told otherwise. This should rule out all XSS problems caused56 in templates, but there are still other places where you have to be57 careful:58 59-- generating HTML without the help of Jinja259+- generating HTML without the help of Jinja60 - calling :class:`~markupsafe.Markup` on data submitted by users61 - sending out HTML from uploaded files, never do that, use the62 ``Content-Disposition: attachment`` header to prevent that problem.63 - sending out textfiles from uploaded files. Some browsers are using64 content-type guessing based on the first few bytes so users could65 trick a browser to execute HTML.66 67 Another thing that is very important are unquoted attributes. While68-Jinja2 can protect you from XSS issues by escaping HTML, there is one68+Jinja can protect you from XSS issues by escaping HTML, there is one69 thing it cannot protect you from: XSS by attribute injection. To counter70 this possible attack vector, be sure to always quote your attributes with71 either double or single quotes when using Jinja expressions in them:72 244 unmodified linesmodified:src/flask/sansio/app.py+1 added-1 removed
519 unmodified lines520 return os.path.join(package_path, "instance")521 return os.path.join(prefix, "var", f"{self.name}-instance")522 523 def create_global_jinja_loader(self) -> DispatchingJinjaLoader:524- """Creates the loader for the Jinja2 environment. Can be used to524+ """Creates the loader for the Jinja environment. Can be used to525 override just the loader and keeping the rest unchanged. It's526 discouraged to override this function. Instead one should override527 the :meth:`jinja_loader` function instead.528 436 unmodified linesmodified:src/flask/templating.py+1 added-1 removed
35 unmodified lines36 return rv37 38 39 class Environment(BaseEnvironment):40- """Works like a regular Jinja2 environment but has some additional40+ """Works like a regular Jinja environment but has some additional41 knowledge of how Flask's blueprint works so that it can prepend the42 name of the blueprint to referenced templates if necessary.43 """44 175 unmodified linesmodified:CHANGES.rst+2 added-2 removed
1374 unmodified lines1375 - The context preservation on exceptions is now an integral component1376 of Flask itself and no longer of the test client. This cleaned up1377 some internal logic and lowers the odds of runaway request contexts1378 in unittests.1379-- Fixed the Jinja2 environment's ``list_templates`` method not1379+- Fixed the Jinja environment's ``list_templates`` method not1380 returning the correct names when blueprints or modules were1381 involved.1382 1383 77 unmodified lines1461 Released 2010-12-311462 1463 - Fixed an issue where the default ``OPTIONS`` response was not1464 exposing all valid methods in the ``Allow`` header.1465-- Jinja2 template loading syntax now allows "./" in front of a1465+- Jinja template loading syntax now allows "./" in front of a1466 template load path. Previously this caused issues with module1467 setups.1468 - Fixed an issue where the subdomain setting for modules was ignored1469 for the static folder.155 unmodified lines