For very large templates it can be useful to not render the whole template at once but evaluate each statement after another and yield piece for piece. This method basically does exactly that and returns a generator that yields one item after another as unicode strings.
(self, *args, **kwargs)
| 1027 | return TemplateStream(self.generate(*args, **kwargs)) |
| 1028 | |
| 1029 | def generate(self, *args, **kwargs): |
| 1030 | """For very large templates it can be useful to not render the whole |
| 1031 | template at once but evaluate each statement after another and yield |
| 1032 | piece for piece. This method basically does exactly that and returns |
| 1033 | a generator that yields one item after another as unicode strings. |
| 1034 | |
| 1035 | It accepts the same arguments as :meth:`render`. |
| 1036 | """ |
| 1037 | vars = dict(*args, **kwargs) |
| 1038 | try: |
| 1039 | for event in self.root_render_func(self.new_context(vars)): |
| 1040 | yield event |
| 1041 | except Exception: |
| 1042 | exc_info = sys.exc_info() |
| 1043 | else: |
| 1044 | return |
| 1045 | yield self.environment.handle_exception(exc_info, True) |
| 1046 | |
| 1047 | def generate_async(self, *args, **kwargs): |
| 1048 | """An async version of :meth:`generate`. Works very similarly but |
no test coverage detected