title: Django/Google Sheets API Model/View Question
body: <p>I'm very new to Python/Django:</p>
  
  <p>I've tested the Google Sheets API by itself and it works. Modifying it slightly, I've placed it in my model as follows:</p>
  
  <pre><code>from __future__ import print_function
  import pickle
  import os.path
  from googleapiclient.discovery import build
  from google_auth_oauthlib.flow import InstalledAppFlow
  from google.auth.transport.requests import Request
  
  # If modifying these scopes, delete the file token.pickle.
  SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly']
  
  # The ID and range of a sample spreadsheet.
  SAMPLE_SPREADSHEET_ID = '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms'
  SAMPLE_RANGE_NAME = 'Class Data!A2:E'
  
  def mainLoop():
      """Shows basic usage of the Sheets API.
      Prints values from a sample spreadsheet.
      """
      creds = None
      # The file token.pickle stores the user's access and refresh tokens, and is
      # created automatically when the authorization flow completes for the first
      # time.
      if os.path.exists('token.pickle'):
          with open('token.pickle', 'rb') as token:
              creds = pickle.load(token)
      # If there are no (valid) credentials available, let the user log in.
      if not creds or not creds.valid:
          if creds and creds.expired and creds.refresh_token:
              creds.refresh(Request())
          else:
              flow = InstalledAppFlow.from_client_secrets_file(
                  'credentials.json', SCOPES)
              creds = flow.run_local_server(port=0)
          # Save the credentials for the next run
          with open('token.pickle', 'wb') as token:
              pickle.dump(creds, token)
  
      service = build('sheets', 'v4', credentials=creds)
  
      # Call the Sheets API
      sheet = service.spreadsheets()
      result = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,
                                  range=SAMPLE_RANGE_NAME).execute()
      values = result.get('values', [])
  
  
      #####################################################
      ##  REMOVED THESE LINES FROM SAMPLE CODE FROM GOOGLE
      #####################################################
  
      #if not values:
      #    print('No data found.')
      #else:
      #    print('Name, Major:')
      #    for row in values:
              # Print columns A and E, which correspond to indices 0 and 4.
      #        print('%s, %s' % (row[0], row[4]))
  
  #if __name__ == '__main__':
  #    main()
  </code></pre>
  
  <p>And I've placed the following in my view:</p>
  
  <pre><code>from django.shortcuts import render
  from django.views import generic
  from django.http import HttpResponse
  from .models import mainLoop
  from django.views.generic import ListView
  
  
  
  def index2(ListView):
      model = mainLoop
      return render('', 'index.html')
  </code></pre>
  
  <p>And here is my html template:</p>
  
  <pre><code>&lt;html&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;head&gt;&lt;/head&gt;
      &lt;body&gt;
  
          &lt;h1&gt;Spreadsheet&lt;/h1&gt;
  
          {% for row in values %}
          &lt;div&gt;
              {% row %}
          &lt;/div&gt;
  {% endfor %}
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And I get the following error:</p>
  
  <pre><code>TemplateSyntaxError at /
  Invalid block tag on line 19: 'row', expected 'empty' or 'endfor'. Did you forget to register or load this tag?
  Request Method: GET
  Request URL:    http://127.0.0.1:8000/
  Django Version: 2.2
  Exception Type: TemplateSyntaxError
  Exception Value:    
  Invalid block tag on line 19: 'row', expected 'empty' or 'endfor'. Did you forget to register or load this tag?
  Exception Location: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/template/base.py in invalid_block_tag, line 522
  Python Executable:  /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
  Python Version: 3.8.2
  Python Path:    
  ['/Users/fred/Documents/googlypie/apisheets',
   '/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip',
   '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
   '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload',
   '/Users/fred/Library/Python/3.8/lib/python/site-packages',
   '/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages']
  Server time:    Fri, 3 Apr 2020 06:49:49 +0000
  </code></pre>
  
  <p>What am I doing wrong here? Can someone please point me in the right direction? Thanks much.</p>