tornado 学习(书籍)
tornado web开发常用类库
sqlalchemy
werkzeug
校验加密密码:check_password_hash
密码加密:generate_password_hash
上传图片
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
class UploadHandler(CommonHandler): def check_xsrf_cookie(self): return True def post(self, *args, **kwargs): files = self.request.files["img"] imgs = [] upload_path = os.path.join( os.path.dirname( os.path.dirname( __file__ ) ), "static/uploads" ) if not os.path.exists(upload_path): os.mkdir(upload_path) for v in files: prefix1 = datetime.datetime.now().strftime("%Y%m%d%H%M%S") prefix2 = uuid.uuid4().hex newname = prefix1 + prefix2 + os.path.splitext(v["filename"])[-1] with open(upload_path + "/" + newname, "wb") as up: up.write(v["body"]) imgs.append(newname) res = dict(ok=1, img=imgs[0]) self.set_header("content-type", "application/json") self.write(json.dumps(res))