我跑的时候
python 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)
我收到以下错误:
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
if __name__=='__main__':
app.run(port=5000,debug=True,use_reloader=True)
要在Ubuntu中启用Flask调试,您可以执行以下操作:为Flask设置环境变量:
$ export FLASK_DEBUG=1
$ export app=app.py # change to whatever the filename is
然后键入以下命令运行Flask-app:
$ run flask
来自docs
缩进事项:
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)