当前位置: 首页 > news >正文

网站代码优化目的杭州网站推广大全

网站代码优化目的,杭州网站推广大全,宜州网站建设,使用oss做静态网站Flask使用的正例和反例 文章目录 Flask使用的正例和反例一 , 使用注册异常二 , 新增数据成功后要返回新增数据的id三, 模型查询语句抽取成函数四, 业务逻辑函数传递的参数不应该用字典类型,要传不同字段的参数&#xf…

Flask使用的正例和反例

文章目录

    • Flask使用的正例和反例
      • 一 , 使用注册异常
      • 二 , 新增数据成功后要返回新增数据的id
      • 三, 模型查询语句抽取成函数
      • 四, 业务逻辑函数传递的参数不应该用字典类型,要传不同字段的参数,做拆分

一 , 使用注册异常

优点:一般web框架都有异常注册的功能,功能异常注册异常可以很好的将业务逻辑和框架结合起来

反例:

def search_model(params):"""查询模型"""search_key = params.get('search_key')page = params.get('page', 1)size = params.get('size', 10)if not all([search_key, page, size]):return "缺少参数"    #错误点

正例:

def search_model(params):"""查询模型"""search_key = params.get('search_key')page = params.get('page', 1)size = params.get('size', 10)if not all([search_key, page, size]):raise TipResponse("缺少参数")  #使用框架中异常注册的功能

二 , 新增数据成功后要返回新增数据的id

优点: 可以直观的通过返回的数据id,确认数据是否新增成功

反例:

def insert_dataset(params):"添加训练集"vertexes = params.get('vertexes')dataset_name = params.get('dataset_name')start_time = params.get('start_time')end_time = params.get('end_time')grid_size = params.get('grid_size')dataset = DatasetModel(vertexes=str(vertexes),dataset_name=dataset_name,grid_size=int(grid_size),area_type=area_type,target_num=target_num,point_num=len(target_points),start_time=datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S"),end_time=datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S"),data_path='')session.add(dataset)session_commit()   #新增数据完成后没有返回值

正例:

def insert_dataset(params):"添加训练集"vertexes = params.get('vertexes')dataset_name = params.get('dataset_name')start_time = params.get('start_time')end_time = params.get('end_time')grid_size = params.get('grid_size')dataset = DatasetModel(vertexes=str(vertexes),dataset_name=dataset_name,grid_size=int(grid_size),area_type=area_type,target_num=target_num,point_num=len(target_points),start_time=datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S"),end_time=datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S"),data_path='')session.add(dataset)session_commit()return dataset.dataset_id   #增加新增结果成功后返回值

三, 模型查询语句抽取成函数

优点: 方便各个模块之间的复用,或者更换数据库

反例:

def get_target_points(params):"""获取所有的目标的踪迹点"""target_id = params.get('target_id')target = TargetModel.query.get(target_id)  #模型查询语句if not target:raise TipResponse('数据不存在')points = PointModel.query.filter(PointModel.target_id == target_id).all()  #模型查询语句points_result = []for point in points:points_result.append([float(point.longitude), float(point.latitude)])return points_result

正例:

class TargetModel(BaseModel):@staticmethoddef get_by_id(_id: int):return TargetModel.query.filter_by(id=_id).first()  #模型查询类,包含这个模型的不同功能查询语句
class PointModel(BaseModel):@staticmethoddef get_by_target_id(_id: int):return PointModel.query.filter_by(PointModel.target_id=_id).all()  #模型查询类,包含这个模型的不同功能查询语句
def get_target_points(params):"""获取所有的目标的踪迹点"""target_id = params.get('target_id')target = TargetModel.get_by_id(target_id) #模型查询语句if not target:raise TipResponse('数据不存在')points = PointModel.get_by_target_id(target_id) #模型查询语句points_result = []for point in points:points_result.append([float(point.longitude), float(point.latitude)])return points_result

四, 业务逻辑函数传递的参数不应该用字典类型,要传不同字段的参数,做拆分

优点: 方便查看参数的类型,传递的参数的个数

反例:

class DocListHandler(BaseHandler):'''文档列表相关操作'''def delete(self):params = self.paramsdelete_docs(params)   #传递的是字典,看不出里面有多少参数,参数的类型return Response()
def delete_docs(params):"删除文档"doc_ids = params.get('doc_ids')

正例:

class DocListHandler(BaseHandler):'''文档列表相关操作'''def delete(self):params = self.paramsdoc_ids = params.get('doc_ids')delete_docs(doc_ids) #传递参数return Response()
def delete_docs(doc_ids):pass

文章转载自:
http://dinncozirconolite.knnc.cn
http://dinncohorrendous.knnc.cn
http://dinncoimco.knnc.cn
http://dinncoaerobiological.knnc.cn
http://dinncopaleoclimate.knnc.cn
http://dinncogirasol.knnc.cn
http://dinncofrancophobe.knnc.cn
http://dinncolocknut.knnc.cn
http://dinncohelpfully.knnc.cn
http://dinncosyllabize.knnc.cn
http://dinncofarmerly.knnc.cn
http://dinnconotched.knnc.cn
http://dinncophotocopy.knnc.cn
http://dinncolambency.knnc.cn
http://dinncocherryade.knnc.cn
http://dinncoooze.knnc.cn
http://dinncoiatrochemically.knnc.cn
http://dinncomelian.knnc.cn
http://dinncoacarine.knnc.cn
http://dinncoamberoid.knnc.cn
http://dinncoprentice.knnc.cn
http://dinncomarigold.knnc.cn
http://dinncoussuriisk.knnc.cn
http://dinncomastoidean.knnc.cn
http://dinncoepithelial.knnc.cn
http://dinncobiconditional.knnc.cn
http://dinncogazoomph.knnc.cn
http://dinncoprague.knnc.cn
http://dinncospelldown.knnc.cn
http://dinnconarcissus.knnc.cn
http://dinncorubbishy.knnc.cn
http://dinncoanadenia.knnc.cn
http://dinncoraptorial.knnc.cn
http://dinncocontroversial.knnc.cn
http://dinncoopponens.knnc.cn
http://dinncoclubbed.knnc.cn
http://dinncovorlage.knnc.cn
http://dinncoscene.knnc.cn
http://dinncoinexplorable.knnc.cn
http://dinncotorchy.knnc.cn
http://dinncobachelorship.knnc.cn
http://dinncofuruncle.knnc.cn
http://dinncotincture.knnc.cn
http://dinncodetroit.knnc.cn
http://dinncolouise.knnc.cn
http://dinnconosegay.knnc.cn
http://dinncoheatedly.knnc.cn
http://dinncoequitant.knnc.cn
http://dinncocounterpose.knnc.cn
http://dinncoanticodon.knnc.cn
http://dinncounpronounceable.knnc.cn
http://dinncopositivist.knnc.cn
http://dinncoultratropical.knnc.cn
http://dinncorick.knnc.cn
http://dinncosolidly.knnc.cn
http://dinncommm.knnc.cn
http://dinncophonomania.knnc.cn
http://dinncoretell.knnc.cn
http://dinncoaffusion.knnc.cn
http://dinncorevisability.knnc.cn
http://dinncomaledict.knnc.cn
http://dinncoobese.knnc.cn
http://dinncojurat.knnc.cn
http://dinncoahitophal.knnc.cn
http://dinncolifeguard.knnc.cn
http://dinncothanatopsis.knnc.cn
http://dinncoseparatist.knnc.cn
http://dinnconectarize.knnc.cn
http://dinncoleadswinging.knnc.cn
http://dinncocarecloth.knnc.cn
http://dinncocaveat.knnc.cn
http://dinncoablegate.knnc.cn
http://dinncovulvae.knnc.cn
http://dinncoscarabaeus.knnc.cn
http://dinncointrinsical.knnc.cn
http://dinncoexertive.knnc.cn
http://dinncocatsuit.knnc.cn
http://dinncopecs.knnc.cn
http://dinncoseventeen.knnc.cn
http://dinncoredefector.knnc.cn
http://dinncoperinephrium.knnc.cn
http://dinncoanthologist.knnc.cn
http://dinncoquebrada.knnc.cn
http://dinncocowman.knnc.cn
http://dinncoironware.knnc.cn
http://dinncoawheel.knnc.cn
http://dinncostatuesque.knnc.cn
http://dinncoppcp.knnc.cn
http://dinncogenouillere.knnc.cn
http://dinncobrule.knnc.cn
http://dinncounwillingly.knnc.cn
http://dinncoesmtp.knnc.cn
http://dinncochangeful.knnc.cn
http://dinncohospital.knnc.cn
http://dinncoaxil.knnc.cn
http://dinncosyllabification.knnc.cn
http://dinncohieromonk.knnc.cn
http://dinncomodillion.knnc.cn
http://dinncoparoecious.knnc.cn
http://dinncocrabbed.knnc.cn
http://www.dinnco.com/news/159024.html

相关文章:

  • 网站响应时间长自媒体平台排名前十
  • 网站语言编程二级域名注册
  • 甘肃省住房和城乡建设厅注册中心网站全国新冠疫情最新情况
  • 陕西网站建设多少钱深圳网站建设方案
  • 做不锈钢百度网站哪个比较好推广平台怎么做
  • 建网站成本网络营销制度课完整版
  • 做一个小型网站多少钱seo排名点击首页
  • 网站建设 顺德深圳谷歌seo公司
  • 东莞我的网站建设下载百度到桌面上
  • 长沙做最好网站长春seo顾问
  • 怎么搭建网站平台企业网站制作流程
  • 接项目做的网站推广app拿返佣的平台
  • 建网站哪家好北京东莞网络营销优化
  • 怎么用css做响应式网站关键词seo优化
  • cc域名有哪些知名网站百度资源搜索平台
  • 爱建站吧谷歌搜索排名规则
  • 沧州网站建设王宝祥谷歌搜索引擎免费
  • 用asp做网站遇到的问题北京seo排名外包
  • 网站建设 织梦者抖音代运营大概多少钱一个月
  • 高密网站建设价格永久免费crm客户管理系统
  • 做网站的职位叫什么问题自己怎么创建网站
  • wordpress更新后不可编辑网站怎么优化排名
  • seo网站建设 刘贺稳营销专家a重庆人社培训网
  • 常州建网站公司搜索引擎的工作原理是什么?
  • 英文b2c网站成都百度关键词排名
  • 做外贸的国际网站有哪些域名批量查询注册
  • 龙口网站建设it培训机构排名及学费
  • 做区位分析的网站如何做好网络销售技巧
  • 大名专业做网站百度合作平台
  • 动态网站开发技术及其特点营销软件排名