实际上是在文件“ D:\ app \ app \ views.py”的第11行说缩进错误@ app.route(“ / api / info”)^IndentationError:unindent与任何外部缩进级别都不匹配从应用程序导入应用程序
from flask import render_template, request
import time
@app.route("/")
def index():
return render_template("index.html")
@app.route("/api/info")
def api_info():
info = {
"ip" : "127.0.0.1",
"hostname" : "everest",
"description" : "Main server",
"load" : [ 3.21, 7, 14 ]
}
return jsonify(info)
@app.route("/api/calc")
def add():
a = int(request.args.get('a', 0))
b = int(request.args.get('b', 0))
div = 'na'
if b != 0:
div = a/b
return jsonify({
"a" : a,
"b" : b,
"add" : a+b,
"multiply" : a*b,
"subtract" : a-b,
"divide" : div,
})
是的,先生,第11行您有缩进错误:
from flask import render_template, request
import time
@app.route("/")
def index():
return render_template("index.html")
# INDENTATION ERROR HERE ON START OF NEXT LINE
@app.route("/api/info")
def api_info():
info = {
"ip" : "127.0.0.1",
"hostname" : "everest",
"description" : "Main server",
"load" : [ 3.21, 7, 14 ]
}
return jsonify(info)
@app.route("/api/calc")
def add():
a = int(request.args.get('a', 0))
b = int(request.args.get('b', 0))
div = 'na'
if b != 0:
div = a/b
return jsonify({
"a" : a,
"b" : b,
"add" : a+b,
"multiply" : a*b,
"subtract" : a-b,
"divide" : div,
})
Just remove the extra beginning 2 spaces on the line with '@app.route("/api/info")'.
将来,使用带有行号的IDE将帮助您缩小这种错误的范围。