May-18-2017, 08:08 AM
I'm trying to follow an online course and while the course content and tutorials are generally good, it's absolutely infuriating to follow because the instructor did not post the source code and for reasons unknown, disabled the discussion section of the course. I keep going over and over and over the code but I cannot find where mine is different. I am getting the error below attempting to create a login screen for a simple web app.
Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/web.py-0.40.dev0-py3.6.egg/web/application.py", line 257, in process return self.handle() File "/usr/local/lib/python3.6/site-packages/web.py-0.40.dev0-py3.6.egg/web/application.py", line 247, in handle fn, args = self._match(self.mapping, web.ctx.path) File "/usr/local/lib/python3.6/site-packages/web.py-0.40.dev0-py3.6.egg/web/application.py", line 495, in _match for pat, what in mapping: ValueError: not enough values to unpack (expected 2, got 1)I suppose that the problem is that I am not sending both the username and password but just one or the other but I'm just speculating here. Application.py is not part of my program, it's part of the "framework" or whatever you call it. I am not sure where to even check my code but I will try to post the stuff that seems the most relevant.
import pymongo, bcrypt from pymongo import MongoClient class LoginModel: def __init__(self): self.client = MongoClient() self.db = self.client.codewizard self.Users = self.db.users def check_user(self, data): user = self.Users.find_one({"username": data.username}) if user: if bcrypt.checkpw(data.password.encode(), user["password"]): return user else: return False else: return False
class CheckLogin: def POST(self): data = web.input() login = LoginModel.LoginModel() isCorrect = login.check_user(data) if isCorrect: return isCorrect return "error"
<div class="container"> <h2>Login</h2> <br /><br /> <form id="login-form"> <div class="form-group label-static is-empty"> <label for="username" class="control-label">Username</label> <input id="username" name="username" class="form-control" type="text" placeholder="Username" /> </div> <div class="form-group label-static is-empty"> <label for="password" class="control-label">Password</label> <input id="password" name="password" class="form-control" type="Password" placeholder="Password" /> </div> <button class="btn btn-raised btn-info waves-effect">Login</button> </form> </div>
$(document).on('submit', '#login-form', function(e){ e.preventDefault(); var form = $(this).serialize(); $.ajax({ url: '/check-login', type: 'POST', data: form, success: function(res){ if (res == "error"){ alert("Could not log in."); }else{ console.log("Logged in as", res); } } }) });Can anyone help?