2017-03-14 35 views
0

我遵循CS50课程,遇到application.py问题。我正在云中的9代码编辑器下面的警告(ACE):云9上的pylint错误消息9 CS50

instance of SQLAlchemy has no column member 
instance of SQLAlchemy has no integer member 
instance of SQLAlchemy has no text member 
instance of scoped_session has no add member 
instance of scoped_session has no commit member 
Class Registrants has no query member 

我创建的主目录的文件.pylintrc并添加以下两行:

ignored-modules=flask_sqlalchemy 
ignored-classes=SQLObject,Registrant 

这摆脱了大多数的错误,但我留下了:

instance of scoped_session has no add member 
instance of scoped_session has no commit member 

下面是导致该问题的代码:

from flask import Flask, render_template, redirect, request, url_for 
from flask_sqlalchemy import SQLAlchemy 

app = Flask(__name__) 

# Flask-SQLAlchemy 
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False 
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///froshims3.db" 
app.config["SQLALCHEMY_ECHO"] = True 
db = SQLAlchemy(app) 

class Registrant(db.Model): 

    __tablename__ = "registrants" 
    id = db.Column(db.Integer, primary_key=True) 
    name = db.Column(db.Text) 
    dorm = db.Column(db.Text) 

    def __init__(self, name, dorm): 
     self.name = name 
     self.dorm = dorm 

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

@app.route("/register", methods=["POST"]) 
def register(): 
    if request.form["name"] == "" or request.form["dorm"] == "": 
     return render_template("failure.html") 
    registrant = Registrant(request.form["name"], request.form["dorm"]) 
    db.session.add(registrant) 
    db.session.commit() 
    return render_template("success.html") 

@app.route("/registrants") 
def registrants(): 
    rows = Registrant.query.all() 
    return render_template("registrants.html", registrants=rows) 

@app.route("/unregister", methods=["GET", "POST"]) 
def unregister(): 
    if request.method == "GET": 
     rows = Registrant.query.all() 
     return render_template("unregister.html", registrants=rows) 
    elif request.method == "POST": 
     if request.form["id"]: 
      Registrant.query.filter(Registrant.id == request.form["id"]).delete() 
      db.session.commit() 
     return redirect(url_for("registrants")) 

回答

1

需要在.pylintrc文件中加入:

ignored-classes=SQLObject,Registrant,scoped_session 

显然Python是创建在运行时的一些类和pylint的是不能选择那些信息了。

对这个答案并不满意,因为它忽略了问题而不是修复它。如果有人有更好的解决方案,请让我知道。 CS50的工作人员正在研究这个问题,但还没有其他解决方案。