Flask Blueprints抛出404,我的路线正确吗?

您好,我尝试复制pypI只是为了学习一些基础知识。我是从视频课程中学到的。现在介绍了蓝图,我无能为力。我总是收到错误404,可惜我的课程不支持其他帮助。有人可以迅速忽略我的代码,然后告诉我我做错了吗?那太好了,可以节省我的夜晚

我在youtube上看到了几个不同的视频,并在此处查找帖子,但我发现了两个。

app.py:

import flask

app = flask.flask(__name__)



def main():
    register_blueprints()
    app.run(debug=True)


def register_blueprints():
    from pypi_org.views import home_views
    from pypi_org.views import package_views

    app.register_blueprint(home_views.blueprint)
    app.register_blueprint(package_views.blueprint)


if __name__ == '__main__':
    main()

home_views.py:

import flask

from pypi_org.infrastructer.view_modifiers import response
import pypi_org.services.package_service as packages_service

blueprint = flask.Blueprint('home',__name__,template_folder='templates')




# #https://github.com/talkpython/data-driven-web-apps-with flask/tree/master/app/ch05_jinja_templates/final/pypi_org/infrastructure 
## I looked at his code but and I did it the same as he did. 


@blueprint.route('')
@response(template_file='home/index.html')
def index():
    test_packages = packages_service.get_latest_packages()
    return {'packages': test_packages}

    # return flask.render_template('home/index.html',packages = test_packages)
    ## Ansonsten ist dies der "normale" Weg.


@blueprint.route('/about')
@response(template_file='home/about.html')
def about():
    return {}

package_views.py:

import flask


from pypi_org.infrastructer.view_modifiers import response
import pypi_org.services.package_service as packages_service

blueprint = flask.Blueprint('packages',template_folder='templates')


@blueprint.route('/package/<package_name>')
#@response(template_file='packages/details.html')
def package_details(package_name: str):
    return 'Package details for {}'.format(package_name)



uyi745 回答:Flask Blueprints抛出404,我的路线正确吗?

我真的需要一些帮助,为什么它不起作用。它让我发疯; _;

本文链接:https://www.f2er.com/3135544.html

大家都在问