烧瓶分类给404个错误的应用程序

发布于 2025-02-11 13:14:36 字数 1362 浏览 1 评论 0原文

我正在浏览此文档: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

留蓝 2025-02-18 13:14:36

将这2行更改为:

@app.route(“/”) @route(“/”)

quotesview.register(app)

QuotesView.register(app, route_base='/')

Change this 2 lines to:

@app.route("/") to @route("/")

QuotesView.register(app) to

QuotesView.register(app, route_base='/')
今天小雨转甜 2025-02-18 13:14:36

您提供的链接中的代码段不包括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 the index 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 before View and make it lowercase). But, again, it's a guess.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文