烧瓶分类给404个错误的应用程序
我正在浏览此文档: https://flask-classful.teracy.org/
上面文档的应用。
from flask import Flask
from flask_classful import FlaskView
# we'll make a list to hold some quotes for our app
quotes = [
"A noble spirit embiggens the smallest man! ~ Jebediah Springfield",
"If there is a way to do it better... find it. ~ Thomas Edison",
"No one knows what he can do till he tries. ~ Publilius Syrus"
]
app = Flask(__name__)
class QuotesView(FlaskView):
@app.route("/")
def index(self):
return "<br>".join(quotes)
QuotesView.register(app)
if __name__ == '__main__':
app.run()
当我运行此应用程序时,它给出了404个错误。
(venv) C:\fifa\web_app_flask_bootstrap>python app.py
* Serving Flask app 'app' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
127.0.0.1 - - [28/Jun/2022 13:44:56] "GET / HTTP/1.1" 404 -
我已经安装了以下瓶相关软件包:
Flask==2.1.2
Flask-Classful==0.14.2
Python version: 3.9.2
显示该错误的原因是什么?
试验1: 更改了端口并尝试了。 app.run(port = 5001)
获得相同的错误。
I am going through this document: https://flask-classful.teracy.org/
Copied minimal app from above document.
from flask import Flask
from flask_classful import FlaskView
# we'll make a list to hold some quotes for our app
quotes = [
"A noble spirit embiggens the smallest man! ~ Jebediah Springfield",
"If there is a way to do it better... find it. ~ Thomas Edison",
"No one knows what he can do till he tries. ~ Publilius Syrus"
]
app = Flask(__name__)
class QuotesView(FlaskView):
@app.route("/")
def index(self):
return "<br>".join(quotes)
QuotesView.register(app)
if __name__ == '__main__':
app.run()
While I am running this app, it is giving 404 error.
(venv) C:\fifa\web_app_flask_bootstrap>python app.py
* Serving Flask app 'app' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000 (Press CTRL+C to quit)
127.0.0.1 - - [28/Jun/2022 13:44:56] "GET / HTTP/1.1" 404 -
I am having following flask related packages installed:
Flask==2.1.2
Flask-Classful==0.14.2
Python version: 3.9.2
What could be the reason for showing that error?
Trial1:
Changed port and tried. app.run(port=5001)
Getting same error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将这2行更改为:
@app.route(“/”)
@route(“/”)quotesview.register(app)
到Change this 2 lines to:
@app.route("/")
to@route("/")
QuotesView.register(app)
to您提供的链接中的代码段不包括
index
函数之前的decorator@app.route('//')
。并且,在摘要之后,立即说:运行此应用程序并将您的Web浏览器打开至:http:// localhost:5000/quotes/quotes/
。我不知道
flask-classful
有效,但我想它以类的名称并将其用作端点(在此示例中,quotesview
查看
并将其制作小写)。但是,这是一个猜测。The code snippet in the link that you provided doesn't include the decorator
@app.route('/')
before theindex
function. And, immediately after the snippet, it say:Run this app and open your web browser to: http://localhost:5000/quotes/
.I don't know how
Flask-Classful
works but I guess that it takes the name of the class and use it as endpoint (in this example,QuotesView
, take all beforeView
and make it lowercase). But, again, it's a guess.