My flask app is outputting 'no content' for the for()
block and i dont know why.
I tested my query in app.py
, here is app.py
:
# mysql config
app.config['MYSQL_DATABASE_USER'] = 'user'
app.config['MYSQL_DATABASE_PASSWORD'] = 'mypass'
app.config['MYSQL_DATABASE_DB'] = 'mydbname'
app.config['MYSQL_DATABASE_HOST'] = 'xxx.xxx.xxx.xxx'
mysql = MySQL()
mysql.init_app(app)
c = mysql.connect().cursor()
blogposts = c.execute("SELECT post_title, post_name FROM mydbname.wp_posts WHERE post_status='publish' ORDER BY RAND() LIMIT 3")@app.route('/', methods=('GET', 'POST'))
def email():form = EmailForm()if request.method == 'POST':if form.validate() == False:return 'Please fill in all fields <p><a href="/">Try Again</a></p>'else:msg = Message("Message from your visitor",sender='[email protected]',recipients=['[email protected]'])msg.body = """From: %s""" % (form.email.data)mail.send(msg)#return "Successfully sent message!"return render_template('email_submit_thankyou.html')elif request.method == 'GET':return render_template('index.html', blogposts)
This is what my app.py
looks like.
Below is my index.html
in templates/
:
<ul>{% for blogpost in blogposts %}<li><a href="{{blogpost[1]}}">{{blogpost[0]}}</a></li>{% else %}<li>no content...</li>{% endfor %}<div class="clearL"> </div></ul>
I checked the query, and it returns desired output like:
ID post_title post_name
1 a title here a-title-here
2 a title here2 a-title-here2
3 a title here3 a-title-here3
If i try to restart the dev server by running export FLASK APP=app.py', then
flask run`, i get an error of:
Error: The file/path provided (app) does not appear to exist. Please verify the path is correct. If app is not on PYTHONPATH, ensure the extension is .py
I've also tried running via export FLASK_APP=app.py
then python -m flask run
- this also gives the same error.
Thoughts on how to resolve?