Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 烧瓶蓝图不';t工作(蟒蛇2)_Python_Flask_Blueprint - Fatal编程技术网

Python 烧瓶蓝图不';t工作(蟒蛇2)

Python 烧瓶蓝图不';t工作(蟒蛇2),python,flask,blueprint,Python,Flask,Blueprint,设置: 我正在尝试克隆git以在本地部署它,并使其用于学术目的。 到目前为止,我只在Python3下使用过Flask,但这个项目是使用Python2在Flask上编写的。设置virtualenv后,安装我可以成功运行的所有需求(pythonServer.py)并导航到索引页面 问题:每当我尝试访问“localhost:5000/login”这样的页面时,我只能看到404错误“找不到”。通过查看代码,我看到它正在导入包含“../login”视图路由的蓝图,但它没有显示它 项目结构如下所示: . ├

设置: 我正在尝试克隆git以在本地部署它,并使其用于学术目的。 到目前为止,我只在Python3下使用过Flask,但这个项目是使用Python2在Flask上编写的。设置virtualenv后,安装我可以成功运行的所有需求(pythonServer.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
这就是在可执行服务器.py(代码片段)内部调用Blueprint的方式:

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

“login”路由是create,因此我希望在导航到“localhost:500/login”后会收到返回的内容,至少是403或其他错误,但不是404(未找到)错误

你能帮我理解我错过了什么吗?
非常感谢您的帮助。

如果您所说的“导航”是指“在浏览器中打开”,那就非常有意义了。
/login
端点上只定义了“POST”动词,浏览器发送GET request.ou,shut。。。你是对的。通过在浏览器中打开
/login
,可以理解为什么我什么都没得到。但是,即使我尝试“导航”到有GET方法的
/login\u check
,我仍然得到404(未找到)。我认为您应该导航到/api/login\u check哦,您完全正确。当我导航/api/login或/api/login\u检查时,它就工作了。谢谢你,现在我知道我错过了什么!
from sfec.api.user import register_user_resource
from sfec.controllers.user import user_api
app.register_blueprint(user_api, url_prefix='/api')
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)