2017-04-25 15 views
-2

7行目で、関数の外に 'return'というエラーが出ます。私はインデントを試してみましたが、問題ではないので何が分かりませんか?'return'関数のエラー - python

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

インデントを確認します。 'return conn'は字下げを持っていますが、どの関数の外にもあります。 – Dmitry

+0

7行目のリターンの前にクリックしてから、Tabキーまたはスペースを4回押します。 – WhatsThePoint

+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) 

私はこれが働くことを願っています。ありがとう。