Opened 14 years ago
Closed 11 years ago
#17093 closed Cleanup/optimization (fixed)
Refactor django.template to quarantine global state
| Reported by: | Carl Meyer | Owned by: | Aymeric Augustin |
|---|---|---|---|
| Component: | Template system | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | bradley.ayers@…, waylan@…, techtonik@…, kmike84@…, tgecho, yac | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The template engine keeps a lot of global state around: the instantiated template loaders, the list of builtins, the cached list of loaded templatetag modules. This makes it inflexible for use as a library (you can't render different templates using different template loaders or directories or tag modules in the same process) and makes test isolation very difficult (for the same reasons).
This can be fixed via a refactoring to introduce a TemplateEngine class to encapsulate all this state. We would still create a default module-level instance of TemplateEngine based on the settings, and backwards-compatibility wrappers for the current public API that delegate to the default engine. But this would then allow alternative instances of TemplateEngine to be created and used for library use and testing, that would be self-contained and independent from settings.
In the long run, this type of refactoring is also necessary if we want to move towards "app-object" style configuration in place of global settings.
Change History (18)
comment:1 by , 14 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 14 years ago
| Cc: | added |
|---|
comment:3 by , 14 years ago
| Cc: | added |
|---|
comment:4 by , 14 years ago
comment:5 by , 14 years ago
| Cc: | added |
|---|
comment:6 by , 14 years ago
| Cc: | added |
|---|
comment:7 by , 14 years ago
| Cc: | added |
|---|
comment:8 by , 13 years ago
| Cc: | added |
|---|
comment:9 by , 13 years ago
| Owner: | changed from to |
|---|
comment:10 by , 13 years ago
See progress of my work at github https://github.com/chrismedrela/django/tree/ticket_17093.
comment:12 by , 13 years ago
I've started discussion at django-developers mailing list https://groups.google.com/d/topic/django-developers/WT1cOvpPbSM/discussion.
comment:13 by , 13 years ago
I rebased my work. I kept old branch and created new one (https://github.com/chrismedrela/django/tree/ticket_17093v2) where I'm pushing my work. The branch is almost ready to review.
comment:14 by , 13 years ago
Please watch new branch (https://github.com/chrismedrela/django/tree/ticket_17093v3).
comment:15 by , 13 years ago
What is the scope of data that should encapsulated in TemplateEngine exactly, and what will be left behind? It is not 100% clear from the description, so I can't say if it will solve my problem with #17368.
comment:16 by , 11 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
I'm picking this up as part of my Multiple Template Engines project.
See https://github.com/aaugustin/django/compare/refactor-template-engine-as-library
I'm going to perform a more intensive cleanup and reorganisation of django.template.
comment:18 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
I assume this can be closed since the PR was committed. Please reopen if there is still more work to do.
For an equivalent API (in C++) see http://www.grantlee.org/apidox/classGrantlee_1_1Engine.html.
It also allows the case of pre-loading template tag modules brought up recently on the devel mailing list.