摘要: 一、__getarribute__方法 __getattribute__(self, name):拦截所有的属性访问操作 >>> class Person: ... def __init__(self, name): ... self.name = name ... def __getattribu 阅读全文
posted @ 2020-04-16 11:49 韩晓萌 阅读(225) 评论(0) 推荐(0) 编辑
摘要: property描述器可以让访问方法时使用属性访问的语法: >>> class Person: ... def __init__(self, name): ... self.__name = name ... def get_name(self): ... return '姓名:' + self._ 阅读全文
posted @ 2020-04-16 11:09 韩晓萌 阅读(213) 评论(0) 推荐(0) 编辑
摘要: 构造方法名字固定为__init__,在创建对象时会自动调用,用于实现类的初始化: >>> class Person: ... def __init__(self, name, age=0): ... self.name = name ... self.age = age ... def get_na 阅读全文
posted @ 2020-04-16 10:40 韩晓萌 阅读(1189) 评论(0) 推荐(0) 编辑
摘要: bytes.decode('unicode_escape') >>> s1 = '\u6ce8\u6768' >>> s1 '注杨' >>> s2 = b'\\u6ce8\\uff1a' >>> s2 b'\\u6ce8\\u6768' >>> print(s2) b'\\u6ce8\\u6768' 阅读全文
posted @ 2020-04-13 17:29 韩晓萌 阅读(1251) 评论(0) 推荐(0) 编辑
摘要: 定义模板: 代码如下: {% extends "admin/base.html" %}{% load i18n %}{% block title %} {{ title }} | {% trans '后台页面标题' %}{% endblock %}{% block branding %} <h1 i 阅读全文
posted @ 2020-04-07 09:57 韩晓萌 阅读(1340) 评论(0) 推荐(0) 编辑
摘要: 假设要包含book表的title字段: search_fields = ['book__title'] 阅读全文
posted @ 2020-04-04 12:36 韩晓萌 阅读(683) 评论(0) 推荐(0) 编辑
摘要: 假设有按下面结构组织的Python程序: /root/ main.py test/ __init__.py test.py math.py test.py如果需要导入包内的math模块: Python 2: import math 或者 from . import math Python 3: fr 阅读全文
posted @ 2020-03-31 19:54 韩晓萌 阅读(374) 评论(0) 推荐(0) 编辑
摘要: 结构化数据 结构固定的数据,例如关系表中存放的数据 半结构化数据 结构不固定的数据,例如HTML、JSON等 非结构化数据 没有结构的数据,例如二进制文件、图片等 阅读全文
posted @ 2020-03-30 18:02 韩晓萌 阅读(2687) 评论(0) 推荐(0) 编辑
摘要: Windows下的Python3.5安装Pillow出现ValueError: zlib is required unless explicitly disabled using --disable-zlib, aborting。 解决方法: pip install --upgrade pip 阅读全文
posted @ 2020-03-28 11:08 韩晓萌 阅读(897) 评论(0) 推荐(0) 编辑
摘要: 模型类为Hero,需求为在Admin中实现Hero类以gender字段进行过滤。 admin.py中的代码如下: from django.contrib import admin from .models import Hero @admin.register(Hero) #注册模型类Hero cl 阅读全文
posted @ 2020-03-23 18:54 韩晓萌 阅读(1946) 评论(2) 推荐(0) 编辑