I have a fairly basic flask set up (been coding using sublime text). For testing purposes, I am now trying to run the following .py file. It contains a query that generates the data: user_data. I am trying to see what the result of that data is.
from datetime import datetime
from flask import Flask, render_template, url_for
import sqlite3
app = Flask(__name__)
db_locale='users.db'
def query_comments():
connie=sqlite3.connect(db_locale)
c=connie.cursor()
c.execute("""
SELECT * FROM comments
""")
user_data=c.fetchall()
print(user_data) #CHANGE THIS TO return user_data
@app.route('/')
@app.route('/home')
def home():
user_data=query_comments() #new variable user_Data that is the result from this query
return render_template('home.html',user_data=user_data)
if __name__ == '__main__':
app.run(debug=True)
On Editing with IDLE and running the file bigquestions.py, it comes up with the following error:
from flask import Flask, render_template, url_for
ModuleNotFoundError: No module named 'flask'
I solved this by opening it in the right python version. IDLE is not the same as what was installed in the venv. It now prints the results of the query correctly.
What still doesn't work:
- Have I made a mistake in the set up or code somewhere? The user_data is NOT being displayed on the webpage.
in the home.html (in templates)
<p><b>{{ sampletext }}</b></p>
<p>{{ user_data }}</p>
...but user_data is not being displayed on the webpage. The above data sampletext works fine, so it isn't a matter of rendering.
I think I've just missed a step or some code, and am not sure what.
The server returns NO errors