dimanche 22 novembre 2015

How to print out query of tuples stored in a list on HTML page

I'm trying to print out some tuples I have stored in a list however I keep getting blank tables. Here is some of my code:

__init__.py:

def view_jobs():
    conn = sqlite3.connect(DBNAME)
    c = conn.cursor()

    c.execute('SELECT * FROM Companies, Job WHERE Companies.cid = Job.cid')

    rows = c.fetchall()

    conn.commit()
    conn.close()
    return rows

web_page.py:

@app.route('/Student/Search', methods=['GET', 'POST'])
def studentSearch():
    table = []
    if request.method == 'POST':
        return render_template('studentsearch.html')
    else: 
        table = adb.view_jobs()
        print table
        return render_template('studentsearch.html', table=table)

studentsearch.html:

<tr>
                    <th>Company Name</th>
                    <th>Company E-mail</th>
                    <th>Internship Position</th>
                    <th>Internship Description</th>

                  </tr>

                  <tr>
                  {% for row in table %}
                    <td>{{row.name}}</td>
                    <td>{{row.email}}</td>
                    <td>{{row.job_type}}</td>
                    <td>{{row.job_description}}</td>
                  {% endfor %}
                  </tr>

when I print to console I get the appropriate data but when I run this I get a site with no data output. The only other experience I have with this is with Django and that seemed to hold the attribute names in place when I passed the array to the HTML but I probably I was probably using something more sophisticated for my queries... Not sure if there is anything specific with flask that I am missing.

I'm thinking the error lies with how I'm passing table but I'm not sure what the best way to do that is

Aucun commentaire:

Enregistrer un commentaire