Creating the Form

Intro to Backend >> Databases >> Creating the Form

Don’t forget to update the line to match your new project’s pathname:


which resides within this line:

template_dir = os.path.join(os.path.dirname(__file__), '/thepathname/toyour/projectsfoldername')

which ultimately resides at the top of the page as you can see here in this code block:

import os
import webapp2
import jinja2

from google.appengine.ext import db

template_dir = os.path.join(os.path.dirname(__file__), '/thepathname/toyour/projectsfoldername')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir),
autoescape = True)

Databases in Python

Intro to Backend >> Databases >> Databases in Python


Here is my explanation of how the line link = link(*link_tuple) comes to be:

print query()

def query()
    cursor = db.execute("select * from links")

#when you iterate over each link in cursor, you are iterating over tuples. aka each link is a tuple. it comes that way from cursor

    for link_tuple in cursor:

#we don't want tuples though. we want objects. so we turn each link_tuple into an object, each called link. but we also want each link to keep the parameters of each link_tuple, so we pass it in in the parenthesis

        link = link(*link_tuple)

#now that each link is an object and not a tuple, we can call whatever parameter name we want to call on it and print it right out!
        print link.votes

print query()