Flask蓝图不起作用(Python2)

2024-04-23 11:17:55 发布

您现在位置:Python中文网/ 问答频道 /正文

设置: 我正在尝试克隆gitproject(all the code here),以便在本地部署它,并使其用于学术目的。 到目前为止,我只有在python3下使用Flask的经验,但是这个项目是使用python2在Flask上编写的。设置virtualenv后,安装我可以成功运行的所有需求(python服务器.py)然后导航到索引页。你知道吗

问题:每当我尝试访问像这样的页面时localhost:5000/登录我只能看到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

这就是Blueprint在可执行文件中的调用方式服务器.py(代码片段):

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

以及用户.py文件(./sfec/controllers)/用户.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”路由是create,所以我希望在导航到本地主机:500/登录'要接收返回的内容,至少是403错误或其他错误,但不是404(未找到)错误。你知道吗

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


Tags: 代码pytxtdecoratorsapiappbaseinit