Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 云9 CS50上的pylint错误消息_Python 3.x_Flask_Flask Sqlalchemy_Pylint - Fatal编程技术网

Python 3.x 云9 CS50上的pylint错误消息

Python 3.x 云9 CS50上的pylint错误消息,python-3.x,flask,flask-sqlalchemy,pylint,Python 3.x,Flask,Flask Sqlalchemy,Pylint,我正在学习CS50课程,在application.py上遇到了问题。我在Cloud 9代码编辑器(Ace)中收到以下警告: 我在主目录中创建了一个文件.pylintrc,并添加了以下两行: ignored-modules=flask_sqlalchemy ignored-classes=SQLObject,Registrant 这消除了大多数错误,但留给我的是: instance of scoped_session has no add member instance of scoped_se

我正在学习CS50课程,在application.py上遇到了问题。我在Cloud 9代码编辑器(Ace)中收到以下警告:

我在主目录中创建了一个文件.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"))

需要添加到.pylintrc文件中:

ignored-classes=SQLObject,Registrant,scoped_session
显然,Python正在运行时创建一些类,而pylint无法获取这些信息


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

使用VSCode,我必须在Python›Linting:Pylint Args设置中添加以下项

--ignored-classes=SQLObject,Registrant,scoped_session
--ignored-classes=SQLObject,Registrant,scoped_session