faq.rst
This file
Path
docs/faq.rst
77 lines · 3.3 KiB
Last changed by
Merge branch 'stable'David Lordbefore adoption6aeab5d
History of this fileTake it
The walk stopped after 200 commits: lines older than c580dd0 point at it.
update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
lines 1–7why, one step back1Frequently Asked Questions2==========================345Why is it called Jinja?6-----------------------7Merge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 8–10why, one step back8"Jinja" is a Japanese `Shinto shrine`_, or temple, and temple and9template share a similar English pronunciation. It is not named after10the `city in Uganda`_.update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
line 11why, one step back11Merge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 12–13why, one step back12.. _Shinto shrine: https://en.wikipedia.org/wiki/Shinto_shrine13.. _city in Uganda: https://en.wikipedia.org/wiki/Jinja%2C_Ugandaupdate building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
lines 14–15why, one step back1415Merge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 16–17why, one step back16How fast is Jinja?17------------------update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
line 18why, one step back18Merge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 19–22why, one step back19Jinja is relatively fast among template engines because it compiles and20caches template code to Python code, so that the template does not need21to be parsed and interpreted each time. Rendering a template becomes as22close to executing a Python function as possible.update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
line 23why, one step back23Merge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 24–28why, one step back24Jinja also makes extensive use of caching. Templates are cached by name25after loading, so future uses of the template avoid loading. The26template loading itself uses a bytecode cache to avoid repeated27compiling. The caches can be external to persist across restarts.28Templates can also be precompiled and loaded as fast Python imports.update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
line 29why, one step back29Merge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 30–34why, one step back30We dislike benchmarks because they don't reflect real use. Performance31depends on many factors. Different engines have different default32configurations and tradeoffs that make it unclear how to set up a useful33comparison. Often, database access, API calls, and data processing have34a much larger effect on performance than the template engine.update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
lines 35–36why, one step back3536Merge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 37–38why, one step back37Isn't it a bad idea to put logic in templates?38----------------------------------------------update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
lines 39–40why, one step back3940Without a doubt you should try to remove as much logic from templates asMerge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 41–46why, one step back41possible. With less logic, the template is easier to understand, has42fewer potential side effects, and is faster to compile and render. But a43template without any logic means processing must be done in code before44rendering. A template engine that does that is shipped with Python,45called :class:`string.Template`, and while it's definitely fast it's not46convenient.update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
line 47why, one step back47Merge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 48–52why, one step back48Jinja's features such as blocks, statements, filters, and function calls49make it much easier to write expressive templates, with very few50restrictions. Jinja doesn't allow arbitrary Python code in templates, or51every feature available in the Python language. This keeps the engine52easier to maintain, and keeps templates more readable.update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
line 53why, one step back53Merge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 54–57why, one step back54Some amount of logic is required in templates to keep everyone happy.55Too much logic in the template can make it complex to reason about and56maintain. It's up to you to decide how your application will work and57balance how much logic you want to put in the template.update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
lines 58–59why, one step back5859Merge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
line 60why, one step back60Why is HTML escaping not the default?update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
lines 61–62why, one step back61-------------------------------------62Merge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 63–64why, one step back63Jinja provides a feature that can be enabled to escape HTML syntax in64rendered templates. However, it is disabled by default.update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
line 65why, one step back65Merge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 66–69why, one step back66Jinja is a general purpose template engine, it is not only used for HTML67documents. You can generate plain text, LaTeX, emails, CSS, JavaScript,68configuration files, etc. HTML escaping wouldn't make sense for any of69these document types.update building docs instructions in contributing guide (#1235)sixtyfathomsbefore adoptionc580dd0
line 70why, one step back70Merge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 71–72why, one step back71While automatic escaping means that you are less likely have an XSS72problem, it also requires significant extra processing during compilingMerge branch 'stable'David Lordbefore adoption6aeab5d
line 73why, one step back73and rendering, which can reduce performance. Jinja uses `MarkupSafe`_ forMerge pull request #1617 from pallets/docs-proseDavid Lordbefore adoption3a050b1
lines 74–75why, one step back74escaping, which provides optimized C code for speed, but it still75introduces overhead to track escaping across methods and formatting.Merge branch 'stable'David Lordbefore adoption6aeab5d
lines 76–77why, one step back7677.. _MarkupSafe: https://markupsafe.palletsprojects.com/