mongoDB:python代码问题

时间:2013-04-10 16:50:51

标签: python mongodb pymongo

可能是错误的瓶子版本吗?

我在管理员提供的sessionDAO文件中被忽略了,他们就像我这样做了;

代码:

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

表示:

[1]连接到{​​{1}} db [2]选择blog集合

在登录代码中我有:

users

我知道自己,用户名和密码;它应该是一个简单的文档查找,就像我写的那样;我现在看到可能存在缩进问题,我只能在stackoverflow上看到它,在notepad ++中它不存在;

def validate_login(self, username, password):

        user = None
        try:
            # XXX HW 2.3 Students Work Here
            # you will need to retrieve right document from the users collection.

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

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

默认情况下,文档已准备好: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}

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

更改行

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

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