#1169 closed enhancement (wontfix)
[patch] Render a template to a file on disk (loader.render_to_disk)
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Template system | Version: | |
Severity: | normal | Keywords: | loader, render_to_disk, render_to_string |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Here's a patch that allows one to render (output, save) a template to a file on disk. Use it in a similar way as you would use loader.render_to_string().
render_to_file loads the given template_name and renders it, with the given dictionary as context, to a file on disk. The template_name may be a string to load a single template using get_template, or it may be a tuple to use select_template to find one of the templates in the list. file_path defines the file that will be written to disk. mode defaults to 'w' which will create the file if it doesn't exist and will overwrite the file if it does exist.
Here's an example use:
from django.core.template import loader path = '/path/to/my/file.txt' template = 'django/path/to/template/name' loader.render_to_file(template_name=template, file_path=path, dictionary={'foo': self.get_foo(), 'bar': Bar(),})
Attachments (1)
Change History (3)
by , 19 years ago
Attachment: | django-core-template-loader.py.diff added |
---|
comment:1 by , 19 years ago
What's the use case for this, and why is it necessary to include this functionality in Django proper, when it can be emulated in two lines of Python code using the normal render()
method?
comment:2 by , 19 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Closing this ticket as a wontfix because my question wasn't answered.
Patch to render a template to file on disk