title: Accessing Class methods in Jinja2 templating
body: <p>I'm using a Flask app in the backend, which is supposed to render a list of SKU (Stock Keeping Unit) codes in the frontend using a loop inside a Jinja2 template. The SKU class is as follows:</p>
  
  <pre><code>class SKU:
  """Class to hold SKU data returned from the database."""
  
  def __init__(self, sku, scanned_at, actual_count, expected_count):
      """Initialize the SKU class with relevant attributes."""
      self.sku = str(sku)
      self.scanned_at = str(scanned_at)
      self.actual_count = int(actual_count)
      self.expected_count = int(expected_count)
  
  def get_progress(self):
      """Get the SKU production progress as a percentage."""
      return ((self.actual_count / self.expected_count) *
              100 if self.expected_count != 0 else 0)
  </code></pre>
  
  <p>I have a method <code>get_all_skus_today()</code> that returns all rows in the database for today's date, as a list of <code>SKU</code> objects. I want to render this when someone accesses <code>/skus</code> with the following route:</p>
  
  <pre><code>@app.route("/skus")
  def skus():
      """Get all SKUs for the day and render the skus.html template."""
      skus = get_all_skus_today()
      return render_template("skus.html", skus=skus)
  </code></pre>
  
  <p>The problem is that I want to show the progress value, that is the return of the function <code>get_progress()</code>, which is not a Class attribute, but a method. I want to do something like this:</p>
  
  <pre><code>{% for sku_row in skus %}
      {{ sku_row.sku }}
      {{ sku_row.get_progress }}
  {% endfor %}
  </code></pre>
  
  <p>But this doesn't work. I want to avoid having to loop through the list of SKU objects and converting them into a tuple to then pass to the <code>render_template</code> function (which is what I was doing before).</p>
  
  <p>Any help greatly appreciated - let me know if you need any further clarification.</p>