3

I have a very simple query (just starting out with SQLAlchemy) and I know that it is working because it prints in the terminal but not on the HTML page, which is the problem.

As follows:

from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import *
from models import db, Candidate, User, Template
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

some_engine = create_engine('databse_url')
Session = sessionmaker(bind=some_engine)
session = Session()

@application.route("/", methods=['GET', 'POST'])
def index():
    res = session.query(Template).all()
    for temp in res:
            print temp.spark_id
    return render_template('index.html')

In the terminal the 2 "spark_id" are printed but on the HTML page I just get nothing.

In the index.html page I have:

% if res %}
    {% for temp in res %}

        <p>{{ temp.spark_id }}</p>
        <p>{{ temp.created_at }}</p>

    {% endfor %}
{% endif %}

What is going wrong?

1 Answer 1

6

You're not passing the query results to your template:

return render_template('index.html', res=res)
Sign up to request clarification or add additional context in comments.

1 Comment

thank you and sorry for being so silly. Very simple, I just did not know. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.