摘要: 迭代器和生成器都可以用来遍历数据集合,但它们在实现上略有不同。下面是关于迭代器和生成器的一些简要介绍: 迭代器(Iterator): 迭代器是一种对象,用于表示一个数据流。它可以用来遍历容器内的元素,如列表、集合、字典等。迭代器通常有两个方法:__iter__和__next__。__iter__方法 阅读全文
posted @ 2024-05-27 16:50 沈柏军 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 装饰器 基本样式 def decorator(func): def wrapper(*args, **kwargs): print("before") res = func(*args, **kwargs) print("after") return res return wrapper @deco 阅读全文
posted @ 2024-05-27 15:05 沈柏军 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 收集静态文件 python manage.py collectstatic 安装django: pip install django 安装依赖 pip install -r requirements.txt 创建项目: django-admin startproject project_name 创 阅读全文
posted @ 2024-05-26 16:34 沈柏军 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 雷池WAF 社区版 | 下一代 Web 应用防火墙 | 免费使用 https://waf-ce.chaitin.cn/docs/guide/install https://www.chaitin.cn/zh/safeline 阅读全文
posted @ 2024-05-25 14:18 沈柏军 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 作 者:刘润 来 源:刘润(ID:runliu-pub) 如果我也出生于96年,年入10个亿…就好了。 可惜,我不是。但有人是。 第一次看到那位96年出生,但已经年入10个亿的创业者时,我有很多话想问。 有些,是关于:96年出生?比我小了整整20岁?哎,年轻真好!想当年我......嗯,还好,我打住 阅读全文
posted @ 2024-05-25 14:05 沈柏军 阅读(8) 评论(0) 推荐(0) 编辑
摘要: 提取目录 import markdown from markdown.extensions.toc import TocExtension def content(request, content_id): content_id = int(content_id) content = Content 阅读全文
posted @ 2024-05-19 16:01 沈柏军 阅读(23) 评论(0) 推荐(0) 编辑
摘要: 一、安装markdown插件 pip install django-mdeditor pip install markdown 二、在 settings 配置文件 INSTALLED_APPS 中添加 mdeditor: INSTALLED_APPS = [ ... 'mdeditor', ] 三、 阅读全文
posted @ 2024-05-18 14:50 沈柏军 阅读(66) 评论(0) 推荐(0) 编辑
摘要: 类的特殊方法 call 假设我们有一个类Calculator,它有一个__call__方法,用来计算两个数的和。代码如下: class Calculator: def __call__(self, a, b): return a + b calc = Calculator() result = ca 阅读全文
posted @ 2024-05-17 08:50 沈柏军 阅读(4) 评论(0) 推荐(0) 编辑
摘要: Flask基本用法 Flask基本结构 # 引入Flask包,使得我们可以创建Flask应用实例 from flask import Flask # 创建一个Flask应用实例。`__name__` 是Python内置变量,它表示当前模块的名称。 # 在这里,`__name__` 被传递给Flask 阅读全文
posted @ 2024-04-23 09:13 沈柏军 阅读(8) 评论(0) 推荐(0) 编辑
摘要: #导入requests包 import requests #会发生重定向的url url = "https://example.com" # 发送带有重定向的HTTP请求 response = requests.get(url, allow_redirects=True) # 获取最终重定向后的UR 阅读全文
posted @ 2024-04-20 16:01 沈柏军 阅读(77) 评论(0) 推荐(0) 编辑