目录结构:
__init__
:
from flask import flask
app = Flask(__name__)
if __name__ == '__main__'
app.run()
查看:
from app import app
@app.route('/')
def hello_world():
return 'Hello World!'
我希望有人能解释我在这里做错了什么 -
我想我不明白如何正确导入app
。这导致404.但是当视图移回__init__
时,一切正常。
答案 0 :(得分:6)
您需要在// When the user hits return, send the "text-entered"
// message to main.js.
// The message payload is the contents of the edit box.
var textArea = document.getElementById("numTimes");
textArea.addEventListener('keyup', function onkeyup(event) {
if (event.keyCode == 13) {
// Remove the newline.
text = textArea.value.replace(/(\r\n|\n|\r)/gm,"");
self.port.emit("text-entered", text);
textArea.value = '';
console.log("Got text from enter");
}
}, false);
// Listen for the "show" event being sent from the
// main add-on code. It means that the panel's about
// to be shown.
//
// Set the focus to the text area so the user can
// just start typing.
self.port.on("show", function onShow() {
textArea.focus();
});
var submit = document.getElementById("search");
submit.addEventListener("click", function submit(){
text = textArea.value.replace(/(\r\n|\n|\r)/gm,"");
self.port.emit("text-entered", text);
textArea.value = '';
console.log("Got text from submit button");
}, false);
中明确导入views
模块:
__init__
如果不导入模块,则永远不会进行视图注册。
将脚本部分保留在包外。在运行开发服务器的from flask import flask
app = Flask(__name__)
from . import views
中(因此在Final_app
目录之外)添加单独的文件;说app
:
run.py