Return a compiled Template object for the given template name, handling template inheritance recursively.
(self, template_name)
| 170 | return Template(template_code, engine=self) |
| 171 | |
| 172 | def get_template(self, template_name): |
| 173 | """ |
| 174 | Return a compiled Template object for the given template name, |
| 175 | handling template inheritance recursively. |
| 176 | """ |
| 177 | original_name = template_name |
| 178 | try: |
| 179 | template_name, _, partial_name = template_name.partition("#") |
| 180 | except AttributeError: |
| 181 | raise TemplateDoesNotExist(original_name) |
| 182 | |
| 183 | if not template_name: |
| 184 | raise TemplateDoesNotExist(original_name) |
| 185 | |
| 186 | template, origin = self.find_template(template_name) |
| 187 | if not hasattr(template, "render"): |
| 188 | # template needs to be compiled |
| 189 | template = Template(template, origin, template_name, engine=self) |
| 190 | |
| 191 | if not partial_name: |
| 192 | return template |
| 193 | |
| 194 | extra_data = getattr(template, "extra_data", {}) |
| 195 | try: |
| 196 | partial = extra_data["partials"][partial_name] |
| 197 | except (KeyError, TypeError): |
| 198 | raise TemplateDoesNotExist(partial_name, tried=[template_name]) |
| 199 | partial.engine = self |
| 200 | |
| 201 | return partial |
| 202 | |
| 203 | def render_to_string(self, template_name, context=None): |
| 204 | """ |