月度归档:2018年08月

github报错failed to push some refs to ‘git

$ git push origin master
Warning: Permanently added the RSA host key for IP address '192.30.253.112' to the list of known hosts.
To git@github.com:Tuesdday/pythoncode.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:Tuesdday/pythoncode.git'
#提交代码时报错
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

继续阅读

Flask下拉列表与数据库同步问题解决记录

刚开始 我的表单是这么写的

forms.py:

tags = Tag.query.all()

class MovieForm(FlaskForm):
    """电影表单"""
    tag_id = SelectField(
        label="标签",
        validators=[DataRequired("请选择标签")],
        description="标签",
        coerce=int,
        choices=[(v.id, v.name) for v in tags],
        render_kw={"class": "form-control"}
    )

在表单类之外 先执行 查询标签的 动作 tags = Tag.query.all(),但是我发现我在另外一个页面添加标签成功之后,返回在电影添加页面 进行tag选取时,下拉框中出现的内容并没有刚才新添加的tag,
怀疑是tags = Tag.query.all()这条语句并没有被调用

继续阅读

FlaskForm自定义验证函数

这是一个用户注册的视图函数:

@home.route("/register/", methods=["GET", "POST"])
def register():
    form = RegisterForm()

    if form.validate_on_submit():
        data = form.data
        user = User(
            name=data["name"],
            email=data["email"],
            phone=data["phone"],
            pwd=generate_password_hash(data["pwd"]),
            uuid=uuid4().hex
        )
        db.session.add(user)
        db.session.commit()
        flash("注册成功", "ok")

用户注册时 怎么验证用户名或者邮箱已经存在呢?

继续阅读