我们已经与flask实现了二合一的后端。对于网站本身(我们称为sum(vector1[-length(vector1)],vector2[-length(vector2)])
),我们没有遇到任何麻烦。但是对于管理门户网站(我们称其为tekid
),即使使用相同的视图注册表,WSGI服务器(开发人员和生产人员)也会为所有请求返回 404 NOT FOUND (未找到)。 / p>
相关代码
CLI条目注册为
-
tekid-admin
->tekid
-
tekid.cli.www:cli
->tekid-admin
以下是我们用于保存flask应用程序对象的代码:
tekid.cli.adm:cli
以下是我们用于CLI输入的代码:
# -*- coding: utf-8 -*-
"""Module entrypoint of TekID website."""
# in `tekid/app/www.py` for `tekid`
from tekid.urls.www import app
# in `tekid/app/adm.py` for `tekid-admin`
from tekid.urls.adm import app
以下是我们用于路由注册表的代码(我们使用的是flask自己提出的集中式注册机制):
# -*- coding: utf-8 -*-
"""CLI for TekID website."""
import click
import flask
import tekid.core.typing as typing
# in `tekid/cli/www.py` for `tekid`
from tekid.app.www import app
# in `tekid/cli/adm.py` for `tekid-admin`
from tekid.app.adm import app
__all__ = ['cli']
@click.group(cls=flask.cli.flaskGroup,create_app=lambda: app)
def cli() -> typing.NoneType:
"""Management script for the TekID website."""
预期行为
注意:# tekid/urls/www.py & tekid/urls/adm.py (same when testing)
# -*- coding: utf-8 -*-
"""URL routing for TekID website."""
# pylint: disable=wrong-import-position
from tekid.core.macro import flaSK as app
__all__ = ['app']
###############################################################################
# load HTML pages
from tekid.urls.pages import * # pylint: disable=unused-wildcard-import
# index.html
app.add_url_rule('/',view_func=load_index)
... # same routing registry codes
和tekid
应该给出相同的输出结果
tekid-admin
命令将如下所示:
routes
我们在网站($ tekid routes
# or
$ tekid-admin routes
Endpoint Methods Rule
-------------- ----------------- -----------------------------------
load_contact GET,POST /contact/
load_expertise GET /expertise/
load_index GET /
load_news GET,POST /news/
...
static GET /static/<path:filename>
)上curl http://127.0.0.1:5000/
之后尝试run
:
tekid
$ tekid run
* Environment: development
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 332-955-135
/fakepath/.venv/lib/python3.7/site-packages/flask/sessions.py:220: UserWarning: The session cookie domain is an IP address. This may not work as intended in some browsers. Add an entry to your hosts file,for example "localhost.localdomain",and use that instead.
"The session cookie domain is an IP address. This may not work"
127.0.0.1 - - [07/Nov/2019 17:20:03] "GET / HTTP/1.1" 200 -
实际行为
使用与上述相同的配置,我们在管理门户($ curl http://127.0.0.1:5000
<!--
_______ _ _____ _____ _ _ _
|__ __| | | |_ _| __ \ | | | | | |
| | ___| | __ | | | | | | | | | |_ __| |
| |/ _ \ |/ / | | | | | | | | | __/ _` |
| | __/ < _| |_| |__| | | |___| || (_| |_
|_|\___|_|\_\_____|_____/ |______\__\__,_(_)
-->
... (the actual HTML page)
)上curl http://127.0.0.1:5000/
之后尝试run
:
tekid-admin
$ tekid-admin run
* Environment: development
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: ***-***-***
/fakepath/.venv/lib/python3.7/site-packages/flask/sessions.py:220: UserWarning: The session cookie domain is an IP address. This may not work as intended in some browsers. Add an entry to your hosts file,and use that instead.
"The session cookie domain is an IP address. This may not work"
127.0.0.1 - - [07/Nov/2019 17:06:25] "GET / HTTP/1.1" 404 -
环境
- Python版本:3.7.4
- 烧瓶版本:1.1.1
- Werkzeug版本:0.16.0