'return'外部函数错误 - python

时间:2017-04-25 10:01:39

标签: python

在第7行,我在函数外面得到错误'return',我尝试了indention,这不是问题,所以我不确定是什么?

 import psycopg2
    from flask import Flask, render_template, request
    app = Flask(__name__)
    def getConn():
        connStr=("dbname='----' user='----' password= '----' " )
    conn=psycopg2.connect(connStr)
    return conn
    @app.route('/')
    def home():
        return render_template('part3.html')
    @app.route('/displayStudent', methods =['GET'])
    def displayCustomer():
        @app.route('/addStudent', methods =['GET', 'POST'])
        def addLeadCustomer():
            if __name__ == "__main__":
                app.run(debug = True)

1 个答案:

答案 0 :(得分:0)

尝试使用:

import psycopg2
from flask import Flask, render_template, request

app = Flask(__name__)
def getConn():
    connStr=("dbname='----' user='----' password= '----' " )
    conn=psycopg2.connect(connStr)
    return conn

@app.route('/')
def home():
    return render_template('part3.html')

@app.route('/displayStudent', methods =['GET'])
def displayCustomer():
    pass

@app.route('/addStudent', methods =['GET', 'POST'])
def addLeadCustomer():
    if __name__ == "__main__":
        app.run(debug = True)

我希望这会奏效。感谢。