mongoDB:python代码issu

2024-03-28 22:19:38 发布

您现在位置:Python中文网/ 问答频道 /正文

可能是瓶子的版本不对吗?在

我查看了管理员提供的sessionDAO文件,他们做的和我做的一样

代码:

def __init__(self, db):
        self.db = db
        self.users = self.db.users
        self.SECRET = 'verysecret'

说:

[1]连接到blog数据库 [2] 选择users集合

在登录代码中我有:

^{pr2}$

我知道self、username和password;这应该是一个简单的按文档查找的方法,正如我写的那样;我现在发现可能有一个缩进问题,我只能在stackoverflow上看到它,而在notepad++中它不存在

以及:

def add_user(self, username, password, email):
            password_hash = self.make_pw_hash(password)

            user = {'_id': username, 'password': password_hash}
            if email != "":
                user['email'] = email

            try:
                # XXX HW 2.3 Students work here
                # You need to insert the user into the users collection.
                # Don't over think this one, it's a straight forward insert.

                self.users.insert(user)

我知道自己,用户名,密码和电子邮件

默认情况下准备文档:user = {'_id': username, 'password': password_hash}

它应该是一个简单的插入:self.users.insert(user)


Tags: the代码文档selfid瓶子dbemail
2条回答

换行

user = self.users.find({"_id":username,"password":password})

user = self.users.find_one({"_id":username})

无论何时对源代码进行任何更改,都需要重新启动服务器才能使这些更改生效。在

相关问题 更多 >