“2019年5月”存档文章有35

Flask 获取客户端访问uri

如果要获取客户端访问的uri,通过Flask获取访客host,采用如下方式:print request.url_root # prints "http://domain1.com/" print request.headers['Host'] # prints "domain1.com"使用request的url_root方法获取客户端的host。参考资料:Handling with mul...

Typescript默认值以及可选参数

可选参数:在参数名后面,冒号前面添加一个问号,则表明该参数是可选的。如下代码:function buildName(firstName: string, lastName?: string) { //lastName为可选参数 if (lastName) return firstName + " " + lastName; else return first...

first_or_404() get_or_404()

first_or_404()返回查询的第一个结果,如果没有结果,则返回None。property_id = PrivateNumberPropertyName.query.filter_by( id=get_value_single.property_name_id).first_or_404().property_idget_or_404()返回指定主键对应的行,如果没有对应的行,则返...

ngFor length

在angular中如何获取数组元素的长度?具体的一些写法如下:<mat-option *ngFor="let item of optionItem" [value]="item.optionValue"> {{item.optionViewValue?length}}</mat-option>或者:<mat-option *ngFor="let item of optionItem" [valu...

*ngFor index

在Angular中*ngFor如何计数呢?具体代码如下:<ul *ngFor="let item of items; index as i"> <li>{{i+1}} {{item}}</li> </ul>可以在Angular 5/6/7中使用。参考资料:ngFor with index as value in attribute

SQLAlchemy多对多的建表方式

首先定义两个表的相关属性:# 私有号码特性 class PrivateNumberProperty(db.Model): __tablename__ = 'private_number_property' id = db.Column(db.Integer, primary_key=True) property_name_id = db.Column(db.Inte...

Set single_parent=True on the relationship().

今天在使用SQLAlchemy查询多对多的时候,出现了如下错误:sqlalchemy.exc.ArgumentError: On PrivateNumberProperty.PrivateNumberTag, delete-orphan cascade is not supported on a many-to-many or many-to-one relationship when singl...

Object of type 'Decimal' is not JSON serializable

最近使用Flask.jsonify()的时候出现如下错误:Object of type 'Decimal' is not JSON serializable出现问题的原因:jsonify()无法处理Decimal数据类型。解决方案:您可以通过在应用json_encoder程序实例上设置属性来覆盖应用程序的JSON编码器:import flask app = flask.Flask(...) ...