[flask]调整 Flask-RESTful 中 reqparse.RequestParser 对 None 值的处理

默认情况下,reqparse.RequestParserNone 的处理结果是: 就算你定义了 required=True,它仍旧会接受客户端提交的 None 不会返回 400 错误码。

这往往违背了我们的初衷:一般对于 required=True 的字段,我们希望在它的值为 None 的时候能够返回 400 错误码,提示该字段不能为 None, 因为 None 值可能会在保存数据的时候引起数据库抛出 NOT NULL 错误。

可以通过定义一个 argument_class 来改变 reqparse.RequestParser 的默认行为:

from flask.ext.restful import reqparse


class Argument(reqparse.Argument):
    """
    继承自 reqparse ...
more ...

《An Introduction to Programming in Go》学习笔记——安装 Go

Date Category go

本文介绍在 Ubuntu 下用包管理器的安装过程:

  1. 安装 go: sudo apt-get install golang
  2. 配置环境变量:
    1. mkdir ~/go ~/go/src ~/go/pkg ~/go/bin # go 工作目录
    2. 在 ~/.bashrc 中加入 export GOPATH=/home/your-user-name/go (注意要把 your-user-name 替换为你本机的用户名,这里 不能使用 ~ 代替 /home/your-user-name
  3. 验证:直接在终端下输入 go 命令就可以了。

其他安装方式以及在其他操作系统下的安装,请参考:https://github.com/astaxie/build-web-application-with-golang/blob/master/ebook ...

more ...