它可能是錯誤的瓶子版本?mongoDB:python代碼問題
我迷戀在管理員提供的sessionDAO文件中,他們做的和我做的一樣;
的代碼:
def __init__(self, db):
self.db = db
self.users = self.db.users
self.SECRET = 'verysecret'
說:
[1]連接到blog
分貝 [2]選擇users
收集
和在登錄碼我有:
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})
我知道自己,用戶名和密碼d密碼;它應該是一個簡單的文檔查找,就像我寫的一樣;我現在看到,可能存在縮進問題,至於我只能在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)
您是否收到任何錯誤? – 2013-04-10 19:34:44
不,無;這很奇怪 – 2013-04-10 19:35:06
如果你運行mongo shell並執行'show dbs;'然後'使用blog;'然後'show collections;'然後'db.users.find();',在這個命令序列中看起來很愚蠢? – 2013-04-10 19:38:54