Network Reliability Engineering Community

Render Method Exact Effect

What is the exact Effect of render method?

In “Using Jinja Lesson 2- For Loops”. We created a for loop to put variables inside our template.

Then we used the render function to put variable inside the same template used in the for loop.

Question is: What if we didn’t use the render function at the end?. What does render exactly do?

Thanks.

So, Jinja -Lab 2 covers the use of for loops WITHIN the template itself. Jinja provides for logic to be used within the template, so you can make decisions there with any data passed in to it.

In this example we aren’t actually using these for loops to provide data into our template, what we’re doing is working with data that’s passed into the template. When we call the render function, we’re creating a finalize output that allows us to pass in whatever data that template might require (in this case, the interfaces list which is defined in the outer Python logic first), and we get an output that results from the logic that the Jinja template uses to process that data.

So, we always need a render function to create some output from a template, and while we’re doing that, we also have the ability to pass data into the template for it to use in its internal logic. That’s why in this lab, we see interfaces=interfaces. This is another way of saying "hey that list I defined in Python, please pass that into my template when you render it.

Hope that helps.

Thanks very much that was totally clear.

I thought jinja is actually creating the template with the interfaces variable. It is just a dummy variable inside Jinja code. Then render will put the variable inside the template.

It is better to differentiate jinja dummy variables from the actual variable to avoid confusion.

Anyway thanks for your answer.