简体   繁体   English

重定向后烧瓶没有重定向到新页面(url_for())

[英]flask not redirecting to new page after redirect(url_for())

I have a simple app that needs to run a subprocess.call in celery and simply return some text to the screen as it's been successfully submitted.我有一个简单的应用程序,需要在 celery 中运行 subprocess.call 并在成功提交后简单地将一些文本返回到屏幕。

Try as I might, I have been unable to make the redirect(url_for()) do anything.尽我所能,我一直无法使重定向(url_for())做任何事情。 I see in the log that I get a 302 and a 200 but no new page in the browser window.我在日志中看到我得到 302 和 200 但浏览器窗口中没有新页面。

Here is my the pertinent part of my server.py code:这是我的 server.py 代码的相关部分:

#!/usr/bin/python

import os
from flask import Flask, url_for, jsonify, request, make_response, render_template, json, flash, Markup, redirect
from celery import Celery, states
from flask_cors import CORS, cross_origin
import pandas as pd
import subprocess

app = Flask(__name__)
CORS(app)
app.secret_key = 'random string'
app.config['CELERY_BROKER_URL'] = 'amqp://cluster:cluster@localhost/myvhost'
app.config['CELERY_RESULT_BACKEND'] = 'amqp://cluster:cluster@localhost/myvhost'
celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
celery.conf.update(app.config)


@app.route('/')
def main():
    return render_template('index.html')

@app.route('/showPrevNext')
def showPrevNext():
    return render_template('prevnext.html')

@app.route('/PrevNext',methods=['GET','POST'])
def prevNext():
    _uid      = request.form['inputUid']
    _db   = request.form['inputName']
    _TableName = request.form['inputTableName']
    if  _id:
        uid = _uid
        if _db:
            db = _db
            if _TableName:
                TableName = _TableName
                flash("Running  images!")
                return redirect(url_for('main'))
                create_some_stuff.delay(uid,db,TableName)

create_some_stuff is a celery task that runs fine but I am having trouble making the redirect work. create_some_stuff 是一个运行良好的芹菜任务,但我无法使重定向工作。 After many hours of toying, I hope one of you can help please?经过几个小时的玩弄,我希望你们中的一个能帮忙吗?

output from the console is:控制台的输出是:

 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger pin code: 270-380-963
192.168.200.238 - - [15/Feb/2018 16:55:07] "POST /PrevNext HTTP/1.1" 302 -
192.168.200.238 - - [15/Feb/2018 16:55:08] "GET / HTTP/1.1" 200 -

Am I missing something simple?我错过了一些简单的东西吗?

Thanks谢谢

I am having trouble making the redirect work.我无法使重定向工作。

Maybe conditional expressions in prevNext doesn't lead to functions return.可能prevNext中的条件表达式不会导致函数返回。 Try to move return to the first level and see what will happen.尝试移动返回到第一级,看看会发生什么。 Like so:像这样:

@app.route('/PrevNext',methods=['GET','POST'])
def prevNext():
    _uid      = request.form['inputUid']
    _db   = request.form['inputName']
    _TableName = request.form['inputTableName']
    if  _id:
        uid = _uid
        if _db:
            db = _db
            if _TableName:
                TableName = _TableName
                flash("Running  images!")
                create_some_stuff.delay(uid,db,TableName)
    return redirect(url_for('main')) #moved

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM