从一个烧瓶应用程序重定向到本地主机上的另一个烧瓶应用程序[复制]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我有两个烧瓶应用程序在本地主机和不同的端口,5000和5001上运行。首先我在端口5000上运行烧瓶应用程序,然后如果我的烧瓶app 1的条件满足,我想将其重定向到index.html运行端口号5001。

我试过返回render_template('http://localhost:5001/index.html'),但它给出了一个错误jinja2.exceptions.TemplateNotFound:http://localhost:5001/index.html

python flask
1个回答
1
投票

这个错误是因为你无法渲染另一个应用程序的模板,因为在这种情况下重定向你可以像下面那样,这是我的烧瓶应用程序,它只是简单地展示如何在应用程序之间重定向

from flask import Flask,redirect
app = Flask(__name__)

@app.route("/")
def test():
    return redirect('http://localhost:5001', code=301)
© www.soinside.com 2019 - 2024. All rights reserved.