title: Flask Get all products from table and iterate over them
body: <p>I'm writing a website that uses Flask as the backend, and I am trying to add all products from a table into the webpage.</p>
  
  <p>I've never used SQLAlchemy or anything like it, so I'm not sure how exactly to get all the products from a database, and then categorize them as I need for the website.</p>
  
  <p>Here is the code I'm using in views.py</p>
  
  <pre><code>@app.route('/products')
  def products():
      product = [
          {
              'product_name': 'T-Shirts',
              'product_price': '18.00',
              'product_img': '',
              'product_description': 'A t-shirt.'
          },
          {
              'product_name': 'TShirts 2',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
          {
              'product_name': 'TShirts 3',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
          {
              'product_name': 'TShirts 4',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
          {
              'product_name': 'TShirts 5',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
          {
              'product_name': 'TShirts 6',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
          {
              'product_name': 'TShirts 7',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
          {
              'product_name': 'TShirts 8',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
          {
              'product_name': 'TShirts 9',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
          {
              'product_name': 'TShirts 10',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
          {
              'product_name': 'TShirts 11',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
          {
              'product_name': 'TShirts 12',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
          {
              'product_name': 'TShirts 13',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
          {
              'product_name': 'TShirts 14',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
          {
              'product_name': 'TShirts 15',
              'product_price': '25.00',
              'product_img': '',
              'product_description': 'A t-shirt, again.'
          },
      ]
      return render_template("products.html",
                             title="Products",
                             products = product)
  </code></pre>
  
  <p>Here is the code in my template (This works perfectly):</p>
  
  <pre><code>{% extends "base.html" %}
  {% block content %}
           &lt;div class="row"&gt;
              &lt;div class="large-4 small-12 columns"&gt;
                  &lt;img src="{{ url_for('static', filename='img/Straight_Up_Performance_Logo.png') }}"&gt;
  
                  &lt;div class="hide-for-small panel"&gt;
                      &lt;h3&gt;Straight Up Racing&lt;/h3&gt;
                      &lt;h5 class="subheader"&gt;Straight Up Racing believes that the best way to get in touch with our customers is for
                      them to call us. Give us a call at (406) 239-4975 to order yours today!
                      &lt;/h5&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;div class="large-8 columns"&gt;
                 &lt;div class="row container1"&gt;
                     {% for product in products %}
                         &lt;div class="large-4 small-4 columns"&gt;
                             &lt;ul class="pricing-table"&gt;
                                 {% if product.product_name %}&lt;li class="title"&gt;{{ product.product_name }}&lt;/li&gt;{% endif %}
                                 {% if product.product_price %}&lt;li class="price"&gt;${{ product.product_price }} + S&amp;H&lt;/li&gt;{% endif %}
                                 {% if product.product_img %}&lt;li class="bullet-item"&gt;{{ product.product_img }}&lt;/li&gt;{% endif %}
                                 {% if product.product_description %}&lt;li class="description"&gt;{{ product.product_description }}&lt;/li&gt;{% endif %}
                             &lt;/ul&gt;
                         &lt;/div&gt;
                     {% endfor %}
                 &lt;/div&gt;
              &lt;/div&gt;
           &lt;/div&gt;
  
  
  {% endblock %}
  </code></pre>
  
  <p>Here is the code that created the Product table:</p>
  
  <pre><code>class Product(db.Model):
      product_id = db.Column(db.Integer, primary_key=True)
      product_name = db.Column(db.String(64), index = True)
      product_price = db.Column(db.Float, index=True)
      product_img = db.Column(db.String(200), index=True)
      product_description = db.Column(db.String(1000), index=True)
  
      def __repr__(self):
          return '&lt;Product %r&gt;' % (self.product_name)
  </code></pre>
  
  <p>My question isn't why it's not currently pulling data from the database, I know it's using what I manually define. I don't know how to go about pulling it from the database using SQLAlchemy?</p>