python 学习

windows下搭建 tornado 环境

 win10 下安装pip

pycharm 安装 第三方python库

pycharm 集成git 

pycharm 集成git官网

Centos 7.X安装 supervisord

Centos7安装Python3的方法

django-rest-framework

 

 

 

 

tornado 学习(书籍)

tornado web开发常用类库

sqlalchemy
werkzeug
  校验加密密码:check_password_hash
密码加密:generate_password_hash


上传图片
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))
View Code

 



posted @ 2018-05-04 23:06  fo0ol  阅读(125)  评论(0编辑  收藏  举报