Loading

上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 21 下一页
摘要: 像一些reils这样的web框架提供自动生成urls的功能,但是Django没有 rest framework为django添加了这一功能,以一种简单、快速、一致的方式 routers必须配合viewset使用 #导包 from rest_framework import routers ''' D 阅读全文
posted @ 2022-09-19 16:09 木子七 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 在dispatch过程中,下列属性可用于 ViewSet : basename - 根url路径 action - 当前动作类型(例如 list , create ). detail - 用于指示当前动作是针对一个列表还是一个对象detail的布尔指示器 suffix - viewset类型的前缀 阅读全文
posted @ 2022-09-17 17:29 木子七 阅读(55) 评论(0) 推荐(0) 编辑
摘要: 很多时候业务需求并不是几个简单的mixin就可以满足,需要我们自定义mixin # get_object源码中字段查询源代码 filter_kwargs = {self.lookup_field: self.kwargs[lookup_url_kwarg]} obj = get_object_or_ 阅读全文
posted @ 2022-09-17 14:42 木子七 阅读(29) 评论(0) 推荐(0) 编辑
摘要: 在python中所有东西都是对象,都是object,函数也不例外 装饰器本身就是一个可调用的函数,装饰器也叫语法糖,在闭包的基础上实现 装饰器的作用:不影响原因函数的功能,还能添加新的功能 装饰器语法 #定义装饰器函数 def decorator(): ... @decorator #使用@加装饰器 阅读全文
posted @ 2022-08-25 17:40 木子七 阅读(40) 评论(0) 推荐(1) 编辑
摘要: 闭包概念: 内部函数对外部函数作用域里变量的引用 函数内的属性,都是有生命周期的,都是在函数执行期间 闭包可以让一个变量长期在内存中不被释放 内部函数的生命周期 def func(): # 外部函数 print('this is func.') def in_func(): # 内部函数 print 阅读全文
posted @ 2022-08-25 10:24 木子七 阅读(42) 评论(0) 推荐(0) 编辑
摘要: python中操作mysql连接、操作、断开都是网络IO #安装支持异步aiomysql的模块 pip3 install aiomysql async def execute(): # 网络IO操作,连接数据库,遇到IO切换任务 conn = await aiomysql.connect('host 阅读全文
posted @ 2022-08-21 23:18 木子七 阅读(53) 评论(0) 推荐(0) 编辑
摘要: 在使用Python代码操作redis时候,连接、操作、断开都是网络IO #安装支持异步redis的模块 pip3 install aioredis async def execute(address, password): # 网络IO操作:创建redis连接 redis = await aiore 阅读全文
posted @ 2022-08-21 23:12 木子七 阅读(56) 评论(0) 推荐(0) 编辑
摘要: uvloop是asyncio的事件循环的替代方案,性能高于默认asyncio的事件循环的效率,相当于提升两倍,效率可以比肩Go pip3 install uvloop import asyncio import uvloop # 使用uvloop替代原因asyncio loop asyncio.se 阅读全文
posted @ 2022-08-21 23:03 木子七 阅读(31) 评论(0) 推荐(0) 编辑
摘要: 对象通过定义__aenter__()和__aexit__()方法对async with语句进行控制 class AsyncConetxtManager: def __init__(self): self.conn = '' async def do_something(self): return ' 阅读全文
posted @ 2022-08-21 22:57 木子七 阅读(28) 评论(0) 推荐(0) 编辑
摘要: 异步迭代器 实现了__aiter__()和__anext__()方法的对象 __anext__()必须返回一个awaitable对象 async for会处理异步迭代器的__anext__()方法返回的可等待对象,直到引发StopAsyncIteration异常 异步可迭代对象 可在async fo 阅读全文
posted @ 2022-08-21 22:47 木子七 阅读(34) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 21 下一页