我烧瓶应用正在输出“没有内容”为for()
块(所提供的文件/路径(应用程序)似乎并不存在),我不知道为什么。瓶应用程序将不会加载app.py
我测试我的查询中app.py
,这里是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)
这是我的app.py
样子。
下面是我index.html
在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>
我检查了查询,并返回像预期的输出:
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
如果我试图通过运行export FLASK APP=app.py', then
烧瓶运行重新启动开发服务器`,我得到一个错误:
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
我也尝试通过export FLASK_APP=app.py
然后python -m flask run
运行 - 这也给出了相同的错误。
思考如何解决?
大后,我得到一个错误,当我运行'出口FLASK_APP = app.py',然后'烧瓶运行'它给了我一个错误'错误:提供的文件/路径(app)似乎不存在'的想法? – Jshee
对不起,我不明白这个问题。你显然已经知道它运行之前,有什么改变? –
我知道,但是在我改变了这个添加'blogposts = blogposts'后,它开始了这个。重申,当我运行'出口FLASK_APP = app.py'然后'烧瓶运行'在我的本地主机上运行它,它给了我那个错误 – Jshee