Python 烧瓶和#x27;t实际上将用户带到不同的页面

Python 烧瓶和#x27;t实际上将用户带到不同的页面,python,flask,Python,Flask,“main”只是我的主页,“/”是url。由于某些原因,我无法在注册完成后返回主页 我还可以确认“此处”和“已注册”是否打印。而且,在我的终端,我得到 127.0.0.1---[23/Apr/2018 23:13:51]“GET/HTTP/1.1”200- 这意味着它应该是主页,因为当我通过html点击页面上的主页链接时,我得到了相同的一行。单击链接也会重定向。它也是相同的路径“/”,所以我不确定当我知道重定向得到确认时,为什么它可以与html一起工作,而不能与flask一起工作 烧瓶的情况是它

“main”只是我的主页,“/”是url。由于某些原因,我无法在注册完成后返回主页

我还可以确认“此处”和“已注册”是否打印。而且,在我的终端,我得到

127.0.0.1---[23/Apr/2018 23:13:51]“GET/HTTP/1.1”200-

这意味着它应该是主页,因为当我通过html点击页面上的主页链接时,我得到了相同的一行。单击链接也会重定向。它也是相同的路径“/”,所以我不确定当我知道重定向得到确认时,为什么它可以与html一起工作,而不能与flask一起工作

烧瓶的情况是它只是停留在注册页面上。没有其他内容,没有抛出错误。就坐在那里

我甚至可以做重定向('main',code=307),它实际上在主页上运行代码。那么,为什么这个简单的重定向不能呈现Senty.html并将用户带到页面

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

@app.route('/signUp',methods=['POST','GET'])
def signUp():
    # still need to create signup class and transfer below code to new file
    conn = mysql.connect()
    cur = conn.cursor()

   try:
        _name = request.form['inputName']
         _email = request.form['inputEmail']
        _password = request.form['inputPassword']

        # validate the received values
        if _name and _email and _password:

            cur.callproc('sp_createUser',(_name,_email,_password,))
            print ("Registered")
            data = cur.fetchall()

            conn.commit()
            json.dumps({'message':'User created successfully !'})
            print('here')
            return redirect(url_for('main'))

    #else:
         #return json.dumps({'html':'<span>Enter the required fields</span>'})

    #except Exception as e:
        #return json.dumps({'error':str(e)})

    finally:
        cur.close() 
        conn.close()
        return redirect(url_for('main'))
@app.route(“/”)
def main():
返回渲染模板('Senty.html')
@app.route('/signUp',methods=['POST','GET'])
def signUp():
#仍然需要创建注册类并将下面的代码传输到新文件
conn=mysql.connect()
cur=连接光标()
尝试:
_name=request.form['inputName']
_电子邮件=请求。表单['inputEmail']
_密码=请求。表单['inputPassword']
#验证接收到的值
如果名称、电子邮件和密码:
cur.callproc('sp_createUser',(\u名称,\u电子邮件,\u密码,))
打印(“注册”)
data=cur.fetchall()
康涅狄格州提交
dumps({'message':'User created successfully!'})
打印('here')
返回重定向(url_for('main'))
#其他:
#返回json.dumps({'html':'Enter the required fields'})
#例外情况除外,如e:
#返回json.dumps({'error':str(e)})
最后:
当前关闭()
康涅狄格州关闭
返回重定向(url_for('main'))
我不知道该去哪里。我觉得我什么都试过了。这也是HTML

<div class="jumbotron">
      <h1>Senty App</h1>
      <form method="POST">
        <label for="inputName" class="sr-only">Name</label>
        <input type="name" name="inputName" id="inputName" class="form-control" placeholder="Name" required autofocus>
        <label for="inputEmail" class="sr-only">Email address</label>
        <input type="email" name="inputEmail" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
        <label for="inputPassword" class="sr-only">Password</label>
        <input type="password" name="inputPassword" id="inputPassword" class="form-control" placeholder="Password" required>

        <button id="btnSignUp" class="btn btn-lg btn-primary btn-block" type="button">Sign up</button>
    </form>
    </div>

Senty应用程序
名称
电子邮件地址
密码
注册

完全有可能函数在
try
之前抛出一个错误,然后再也无法到达finally?也有可能你在
中做的一些事情最终出现了错误,然后你就再也无法重定向了。你最好的办法是把事情孤立起来,从最基本的情况下继续尝试。@Alper有一次我把“return redirect(url_for('main'))”放在函数的顶部,并注释掉了所有内容,但它仍然没有把我带到主页。这不是我写的,是队友写的。使用post和get方法是否有任何问题?然后减少
url\u for
函数,使其成为一个硬url?请确定,您是否已从flask import url\u for,redirect导入重定向和url\u for