简体   繁体   English

python瓶框架超出最大递归深度

[英]python bottle framework maximum recursion depth exceeded

I am trying to add a path for my web app but for some reason maximum recursion depth error occurs 我正在尝试为我的Web应用程序添加路径但由于某种原因发生最大递归深度错误

def runSQL(sql):
    db = sqlite3.connect('zadanie.db')
    c = db.cursor()
    c.execute(sql)
    data = c.fetchall()
    db.commit()
    c.close()
    return data  

def Subjects(): 
    sql = "SELECT (here is my query)" 
    data = runSQL(sql) 
    return data

@app.route('/subjects')
def Subjects():
    sub = template('look4.html', rows=Subjects())              
    return sub

I have tried to set recursion limit to higher number, but then error segmentation fault 11 occurs. 我试图将递归限制设置为更高的数字,但随后出现错误分段错误11。
I would be grateful for any debugging suggestions :) 我将不胜感激任何调试建议:)

The problem is not with the recursion depth . 问题不在于递归深度 As you can see you define two functions named Subject . 如您所见,您定义了两个名为Subject函数。

As a result Python will override the first one with the second. 因此,Python将使用第二个覆盖第一个。 Now the second one has a call to (what you think is) the previous one. 现在第二个呼叫(你认为)前一个。 But since Subjects is overriden, it will redirect to that function again so: 但是由于Subjects被覆盖,它将再次重定向到该函数,因此:

@app.route('/subjects')
def Subjects():
    sub = template('look4.html', rows=Subjects())
    return sub

Will get stuck in infinite recursion. 将陷入无限递归。 The solution is to simply rename one of the two (probably it is better to rename the first one), and change the call, like: 解决方案是简单地重命名两个中的一个(可能最好重命名第一个),并更改调用,如:

def subjects_query(): 
    sql = "SELECT (here is my query)" 
    data = runSQL(sql) 
    return data

@app.route('/subjects')
def subjects():
    sub = template('look4.html', rows=subjects_query())              
    return sub

Also the convention is that functions in Python are lowercase with underscores, so you better rename the second one to subjects (like I have done here). 此外,惯例是Python中的函数是带有下划线的小写,因此您最好将第二个重命名为subjects (就像我在这里所做的那样)。

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

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