[英]why flask auto debug not working in ubuntu
When I run当我跑
python app.py
where content of app.py
is: app.py
内容在app.py
:
from flask import Flask ,render_template
from data import articles
app=Flask(__name__)
Articles=articles()
@app.route('/')
def index():
return render_template('home.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/articles')
def articles():
return render_template('articles.html',articles=Articles)
@app.route('/article/<string:id>/')
def article(id):
return render_template('article.html',id=id)
if __name__=='__main__':
app.run(debug=True)
I get the following error:我收到以下错误:
Traceback (most recent call last):
File "app.py", line 32, in <module>
app.run(debug=True)
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in > _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error:
/home/haseeb/Documents/Flask/flask_web/app.py
To enable debugging for Flask in Ubuntu you can do the following: Set environment variables for Flask:要在 Ubuntu 中为 Flask 启用调试,您可以执行以下操作: 为 Flask 设置环境变量:
$ export FLASK_DEBUG=1
$ export app=app.py # change to whatever the filename is
Then run your Flask-app by typing:然后输入以下命令运行 Flask 应用程序:
$ run flask
if __name__=='__main__':
app.run(port=5000,debug=True,use_reloader=True)
Indentation matters:缩进问题:
from flask import Flask ,render_template
from data import articles
app=Flask(__name__)
Articles=articles()
@app.route('/')
def index():
return render_template('home.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/articles')
def articles():
return render_template('articles.html',articles=Articles)
@app.route('/article/<string:id>/')
def article(id):
return render_template('article.html',id=id)
if __name__=='__main__':
app.run(debug=True)
This worked for me: On terminal before running flask, run the following commands:这对我有用:在运行 Flask 之前的终端上,运行以下命令:
$ export FLASK_DEBUG=1
$ export app=app.py
Then:然后:
flask run
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.