自定制property class Lazyproperty: def __init__(self,func): # print('==========>',func) self.func=func def __get__(self, instance, owner): print('get') # print(instance) # print(owner) if instance is None: return self res=self.func(instance) setattr(ins…
templates 讲后台得到的数据渲染到页面上:话不多说,先看具体代码. urls: from django.conf.urls import url from django.contrib import admin from django.urls import path from a00 import views urlpatterns = [ path('admin/', admin.site.urls), url(r'show_time/',views.show_time ), url…
Django框架中的urls配置: 首先通过pycharm创建一个Django项目: 例如要写blog的功能:则在digango_lesson中的urls代码如下: """django_lesson URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.0/topics…
Python 链接数据库: 需要先安装pymysql 包 可以设置中安装,也可以pip install pymysql 安装 加载驱动: import pymysql # 需要先安装pymysql 包 可以设置中安装,也可以pip install pymysql 安装 conn = pymysql.connect(host=', db='s3') # 加载驱动 #cursor = conn.cursor() # 创建游标 cursor = conn.cursor(cursor=pymysql.c…
多表查询: 内连接查询: 首先:创建两个表一个为tableA,一个为tableB,并且插入数据(代码省略) 同时查询两个表的记录: select * from tableA,tableB; 根据tableA中id 等于 tableB 中refer_id 进行内连接查询: select * from tableA,tableB where tableA.id=tableB.refer_id; 也可以用一下方法进行内连接查询: select * from tableB inner join tabl…
外键:主要是关联两个表的 举个栗子:在建表中创建外键 -- 添加外键例子 CREATE TABLE teacher( id TINYINT PRIMARY KEY auto_increment, name ), age int, is_marryed boolean ); CREATE TABLE student( id TINYINT PRIMARY KEY auto_increment, name ), charger_id TINYINT, FOREIGN KEY (charger_id)…
记录基本操作: 增:(insert into) 基本语法: insert into 表名(字段) values(对应字段的值): 例子1: insert into employee(id,name,age,salary) values(1,"憨憨",24,5000); 指定添加insert into employee values(2,"憨憨",0,24,"技术部",5000); 对应添加 insert into employee set nam…
python函数局部变量如何改变外部变量,之前我说过,局部变量是没办法改变外部变量的,除非局部变量找不到,去外部找,输出变量,使用关键词global 使变量改变外部变量. 1,使用关键词global name='this is a girl' def chan_sex(): global name name=''this is a boy’ print(name) chan_sex() print(name) 输出结果 :this is a boy 输出结果:this is a boy 注意使用…
python函数参数传递,位置参数,默认参数,关键词参数,最后介绍一个非固定参数,就可以向函数传递一个列表,元组,字典,具体看看用法 1,有一个* 号的参数情况 def goos_stu(id,*user): for u in user          print(u) goos_stu(1,'xiaomi','jimu','dat') 或者传递列表形式 def goos_stu(id,*user): for u in user          print(u) goos_stu(1,*['…
MyWeb框架: from wsgiref.simple_server import make_server def application(environ, start_response): print(environ) start_response('200 OK', [('Content-Type', 'text/html')]) return [b'<h1> Hello,web! </h1>'] httpd = make_server('',8080,application…