首页 > 解决方案 > 烧瓶蓝图不起作用(Python2)

问题描述

设置: 我正在尝试克隆 git项目(此处的所有代码)以在本地部署它并使其用于学术目的。到目前为止,我只在 Python 3 下使用过 Flask,但这个项目是使用 Python 2 在 Flask 上编写的。设置 virtualenv 后,安装所有要求我可以成功运行(python server.py)它并导航到索引页面。

问题:每当我尝试访问“localhost:5000/login”之类的页面时,我只能看到 404 错误“未找到”。查看代码,我看到它正在导入包含到“.../login”视图的路线的蓝图,但它没有达到显示它的地步。

项目结构如下所示:

.
├── API Documentation.md
├── app.py
├── app.pyc
├── data
│   ├── samples
│   │   ├── categories.txt
│   │   ├── domains.txt
│   │   ├── names.txt
│   │   ├── products.txt
│   │   └── surnames.txt
│   └── sql
│       └── schema-00.sql
├── Makefile
├── README.md
├── requirements.txt
├── server.py
├── sfec
│   ├── api
│   │   ├── base.py
│   │   ├── base.pyc
│   │   ├── decorators.py
│   │   ├── decorators.pyc
│   │   ├── fields.py
│   │   ├── fields.pyc
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── order.py
│   │   ├── order.pyc
│   │   ├── product.py
│   │   ├── product.pyc
│   │   ├── user.py
│   │   └── user.pyc
│   ├── config.py
│   ├── config.pyc
│   ├── controllers
│   │   ├── decorators.py
│   │   ├── decorators.pyc
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── order.py
│   │   ├── order.pyc
│   │   ├── user.py
│   │   └── user.pyc
│   ├── database
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── runtime.py
│   │   ├── runtime.pyc
│   │   ├── settings.py
│   │   └── settings.pyc
│   ├── __init__.py
│   ├── __init__.pyc
│   └── models
│       ├── base.py
│       ├── base.pyc
│       ├── __init__.py
│       ├── __init__.pyc
│       ├── order.py
│       ├── order.pyc
│       ├── product.py
│       ├── product.pyc
│       ├── user.py
│       ├── user.pyc
│       ├── views.py
│       └── views.pyc
├── sfecadmin.py
├── templates
│   └── index.html
├── tests
│   ├── __init__.py
│   └── user_test.py
├── tree.txt
└── uml_diagram.png

10 directories, 63 files

这就是在可执行 server.py(代码片段)中调用蓝图的方式:

from sfec.api.user import register_user_resource
from sfec.controllers.user import user_api
app.register_blueprint(user_api, url_prefix='/api')

并且 user.py 文件(./sfec/controllers/user.py)包含(代码片段):

user_api = Blueprint('user_api', __name__)
@user_api.route('/login', methods=['POST'])
def login():
    print "login page"
    """Log the user in."""
    store = get_default_store()
    user = User.authenticate(store, request.form['email'],request.form['password'])
    if user:
        session['user'] = user.id
        return user.json()
    abort(403)

'login' 路由已创建,所以我希望在导航到 'localhost:500/login' 后会收到一些回复,至少是错误 403 或其他内容,但不是 404(未找到)错误。

你能帮我理解我错过了什么吗?我将非常感谢任何帮助。

标签: pythonflaskblueprint

解决方案


推荐阅读