urls = (
'/', 'Home',
'/register', 'Register',
'/login', 'Login',
'/logout', 'Logout',
'/postregistration', 'PostRegistration',
)
app = web.application(urls, globals())
session = web.session.Session(app, web.session.DiskStore("session"), initializer={"user": None})
session_data = session._initializer
render = web.template.render("Views/Templates", base = "Main",
globals={'session': session_data, 'current_user': session_data["user"]})
class PostRegistration:
def POST(self):
data = web.input()
reg_model = RegisterModel.RegisterModel()
reg_model.insert_user(data)
return data.username
'''
RegistrationModel.py
'''
class RegisterModel:
def __init__(self):
self.client = MongoClient()
self.db = self.client.codewizard
self.Users = self.db.users
def insert_user(self, data):
hashed = bcrypt.hashpw(data.password.encode(), bcrypt.gensalt())
id = self.Users.insert({"username": data.username, "name": data.name, "password": hashed,
"email": data.email, "avatar": "", "background": "", "about": "",
"hobbies": "", "birthday": ""})
print("uid is", id)
'''
Register.html
'''
<div class = "container">
<h2>Register Account</h2>
<br /><br />
<form id="register-form">
<div class="form-group label-static is-empty">
<label for="username" class="control-label">Username</label>
<input name = "username" id = "username" class = "form-control" type = "text" placeholder = "Choose a username" />
</div>
<div class="form-group label-static is-empty">
<label for="display_name" class="control-label">Full Name</label>
<input name = "display_name" id = "display_name" class = "form-control" type = "text" placeholder = "Enter your full name" />
</div>
<div class="form-group label-static is-empty">
<label for="email" class="control-label">Email Address</label>
<input name = "email" id = "email" class = "form-control" type = "email" placeholder = "Enter your email" />
</div>
<div class="form-group label-static is-empty">
<label for="password" class="control-label">Password</label>
<input name = "password" id = "password" class = "form-control" type = "password" placeholder = "Make a password" />
</div>
<button type = "submit" class = "btn btn-info waves-effect">Submit</button>
</form>
很清楚,除了最后一行,代码中的每一行都有效。我可以看到选择了前五个工作表,并且Excel甚至有一个正在填充的“发布”窗口。但是,它无法输出任何内容,并且我得到了(-2147352567,'发生了异常。'....)