【问题标题】:Flask Blueprints throws 404, are my routes correct?Flask Blueprints 抛出 404,我的路线是否正确?
【发布时间】:2020-03-05 10:40:46
【问题描述】:

您好,我尝试复制 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', __name__, 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)



【问题讨论】:

    标签: python flask pycharm


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-06-12
      • 1970-01-01
      • 2019-12-25
      • 1970-01-01
      • 2018-10-18
      • 1970-01-01
      • 1970-01-01
      • 2012-06-28
      • 2021-07-29
      相关资源
      最近更新 更多