“2018年2月”存档文章有28

TypeError: html_params() got multiple values for keyword argument 'name'

最近在使用Flask编写代码的时候问题多多,前面一个问题解决,后面一个问题又来了,哎!代码又报错,错误信息如下:html_params() got multiple values for keyword argument 'name'出现这个问题的原因是使用模板的时候已经定义了name,这里又重新定义,所以出现了这个错误。错误代码如下:<div class="form-group"> <la...

There is no index in the referenced table where the referenced columns appear as the first columns

最近在使用alembic更新数据库的时候,提示如下错误:sqlalchemy.exc.IntegrityError: (_mysql_exceptions.IntegrityError) (1215, 'Cannot add foreign key constraint') [SQL: 'ALTER TABLE users ADD FOREIGN KEY(city) REFERENCES `CH_...

raise util.CommandError("Target database is not up to date.")

最近在用Flask-Migrate做数据更新的时候,报如下错误:raise util.CommandError("Target database is not up to date.")alembic.util.exc.CommandError: Target database is not up to date.出现这个错误的原因:因为改变了数据库之后,生成了代码,但是没有向数据库更新或者更新失...

select2 ajax加载数据后不能选中的标签选项

最近在用select2做省市联动,在使用select2的时候遇到了很多问题,现在问题解决了,将解决的过程记录下来,防止后人再犯相同错误。实际实现效果,如下动图:首先是第一个select表单,实现方式是直接通过后台(Python Flask)数据库循环填充,代码如下:<div class="form-group"> <label class="control-label visible-ie8...

TypeError: Object of type 'CH_REGION' is not JSON serializable

最近在写代码的时候,老是提示:Object of type 'CH_REGION' is not JSON serializable代码内容如下:@auth.route('/country', methods=['GET', 'POST']) def country(): ID = request.values.get('country', 0) city = CH_REGI...

TypeError: dump() missing 1 required positional argument: 'fp'

最近要把数据转换成json的时候报错,内容如下:dump() missing 1 required positional argument: 'fp'打码如下:@auth.route('/country', methods=['GET', 'POST']) def country(): ID = request.values.get('country', 0) city = ...

Flask通过数据库填充select标签

最近要用Flask做一个省市二级联动的Select选择,数据从数据库里面读出,详细代码如下:@auth.route('/register', methods=['GET', 'POST']) def register(): form = RegistrationForm() name = '用户注册' ch_region = CH_REGION.query.filt...

python 的特殊方法 __str__和__repr__

__repr__和__str__这两个方法都是用于显示的,__str__是面向用户的,而__repr__面向程序员。打印操作会首先尝试__str__和str内置函数(print运行的内部等价形式),它通常应该返回一个友好的显示。__repr__用于所有其他的环境中:用于交互模式下提示回应以及repr函数,如果没有使用__str__,会使用print和str。它通常应该返回一个编码字符串,可以用来重...