带前缀的FlaskUrl

2024-05-16 01:29:38 发布

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

我有一个Flask应用程序,它将作为服务器的“子部分”运行,我不确定如何配置它。在

例如: localhost/OtherServer/rest/myFlask/

OtherServer是一个IIS网站,通常处理我的所有请求,但对于某些请求,控制权交给Flask-例如,在myFlask/*下找到的所有路由。在

这要感谢WFASTCGI和一些配置魔法,但是在Flask中,我必须为每个路由提供完整的URL: @app.route('/OtherServer/rest/myFlask/status')

我只想指定包含myFlask或myFlask之后的部分,特别是因为url的第一部分在C#应用程序中是可配置的,在运行时获取名称是一个非常头疼的问题。 所以:

@app.route('/myFlask/status')

Tags: 服务器restapp应用程序localhostflask路由网站
1条回答
网友
1楼 · 发布于 2024-05-16 01:29:38

您可以使用blueprint,使用url_prefix参数。在


我给你举个简单的例子:

view.py

from flask import Blueprint

my_blueprint = Blueprint('my_blueprint', __name__, template_folder='templates', 
                         url_prefix='/OtherServer/rest')


@my_blueprint.route('/myFlask/status')
def index():
    return 'Hello, world.'

...other routes...

在您的app.py中,您可以

^{pr2}$

相关问题 更多 >