-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1893 lines (670 loc) · 194 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html class="theme-next mist use-motion" lang="en,zh-tw,default">
<head><meta name="generator" content="Hexo 3.8.0">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">
<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">
<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">
<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">
<link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">
<meta name="keywords" content="Hexo, NexT">
<meta name="description" content="always belive that something wonderful is about to happen">
<meta property="og:type" content="website">
<meta property="og:title" content="blog">
<meta property="og:url" content="http://yoursite.com/index.html">
<meta property="og:site_name" content="blog">
<meta property="og:description" content="always belive that something wonderful is about to happen">
<meta property="og:locale" content="en">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="blog">
<meta name="twitter:description" content="always belive that something wonderful is about to happen">
<script type="text/javascript" id="hexo.configurations">
var NexT = window.NexT || {};
var CONFIG = {
root: '/',
scheme: 'Mist',
version: '5.1.4',
sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
fancybox: true,
tabs: true,
motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
duoshuo: {
userId: '0',
author: 'Author'
},
algolia: {
applicationID: '',
apiKey: '',
indexName: '',
hits: {"per_page":10},
labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
}
};
</script>
<link rel="canonical" href="http://yoursite.com/">
<title>blog</title>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="en">
<div class="container sidebar-position-left
page-home">
<div class="headband"></div>
<header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-wrapper">
<div class="site-meta ">
<div class="custom-logo-site-title">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<span class="site-title">blog</span>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<p class="site-subtitle">student's blogs</p>
</div>
<div class="site-nav-toggle">
<button>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
</button>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section">
<i class="menu-item-icon fa fa-fw fa-home"></i> <br>
Home
</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section">
<i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
Archives
</a>
</li>
<li class="menu-item menu-item-categories">
<a href="/categories" rel="section">
<i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br>
Categories
</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tag" rel="section">
<i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br>
Tags
</a>
</li>
<li class="menu-item menu-item-about">
<a href="/about" rel="section">
<i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br>
About
</a>
</li>
<li class="menu-item menu-item-commonweal">
<a href="/404.html" rel="section">
<i class="menu-item-icon fa fa-fw fa-question-circle"></i> <br>
Commonweal 404
</a>
</li>
</ul>
</nav>
</div>
</header>
<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
<div id="content" class="content">
<section id="posts" class="posts-expand">
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/04/01/django/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Cedar Chen">
<meta itemprop="description" content>
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="blog">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/04/01/django/" itemprop="url">django</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Post created" itemprop="dateCreated datePublished" datetime="2019-04-01T19:54:05+08:00">
2019-04-01
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="入门"><a href="#入门" class="headerlink" title="入门"></a>入门</h1><p><img src="/images/Django框架.png"></p>
<h2 id="虚拟环境"><a href="#虚拟环境" class="headerlink" title="虚拟环境"></a>虚拟环境</h2><h3 id="虚拟环境安装"><a href="#虚拟环境安装" class="headerlink" title="虚拟环境安装"></a>虚拟环境安装</h3><p>1)sudo pip install virtualenv #安装虚拟环境<br>2)sudo pip install virtualenvwrapper #安装虚拟环境扩展包<br>3)编辑家目录下面的.bashrc文件,添加下面两行。<br>export WORKON_HOME=$HOME/.virtualenvs<br>source /usr/local/bin/virtualenvwrapper.sh<br>4)使用source .bashrc使其生效一下。</p>
<h3 id="虚拟环境使用"><a href="#虚拟环境使用" class="headerlink" title="虚拟环境使用"></a>虚拟环境使用</h3><p>创建虚拟环境命令:<br> mkvirtualenv 虚拟环境名<br>创建python3虚拟环境:<br>mkvirtualenv -p python3 bj11_py3<br>进入虚拟环境工作:<br> workon 虚拟环境名<br>查看机器上有多少个虚拟环境:<br> workon 空格 + 两个tab键<br>退出虚拟环境:<br> deactivate<br>删除虚拟环境:<br> rmvirtualenv 虚拟环境名<br>虚拟环境下安装包的命令:<br>pip install 包名<br>查看虚拟环境中安装了哪些python包:<br> pip list<br> pip freeze<br>安装django环境:<br> pip install django==1.8.2</p>
<h2 id="项目创建"><a href="#项目创建" class="headerlink" title="项目创建"></a>项目创建</h2><h3 id="创建项目名"><a href="#创建项目名" class="headerlink" title="创建项目名"></a>创建项目名</h3><p>命令:django-admin startproject 项目名<br>项目目录如下:<br>├── manage.py<br>└── test1<br> ├── <strong>init</strong>.py<br> ├── <strong>pycache</strong><br> │ ├── <strong>init</strong>.cpython-36.pyc<br> │ ├── settings.cpython-36.pyc<br> │ ├── urls.cpython-36.pyc<br> │ └── wsgi.cpython-36.pyc<br> ├── settings.py<br> ├── urls.py<br> └── wsgi.py</p>
<p><strong>init</strong>.py: 说明test1是一个python包。<br>settings.py: 项目的配置文件。<br>urls.py: 进行url路由的配置。<br>wsgi.py: web服务器和Django交互的入口。<br>manage.py: 项目的管理文件。</p>
<h3 id="创建Django应用"><a href="#创建Django应用" class="headerlink" title="创建Django应用"></a>创建Django应用</h3><p>创建应用的命令如下:<br>python manage.py startapp 应用名<br>注意:创建应用时需要先进入项目目录。<br>应用目录如下:<br>.<br>├── admin.py<br>├── <strong>init</strong>.py<br>├── migrations<br>│ ├── <strong>init</strong>.py<br>│ └── <strong>pycache</strong><br>│ └── <strong>init</strong>.cpython-36.pyc<br>├── models.py<br>├── <strong>pycache</strong><br>│ ├── admin.cpython-36.pyc<br>│ ├── <strong>init</strong>.cpython-36.pyc<br>│ └── models.cpython-36.pyc<br>├── tests.py<br>└── views.py<br><strong>init</strong>.py: 说明目录是一个Python模块。<br>models.py: 写和数据库项目的内容, 设计模型类。<br>views.py: ,接收请求,进行处理,与M和T进行交互,返回应答。<br>定义处理函数,视图函数。<br>tests.py: 写测试代码的文件。<br>admin.py: 网站后台管理相关的文件。</p>
<h3 id="应用注册"><a href="#应用注册" class="headerlink" title="应用注册"></a>应用注册</h3><p>建立应用和项目之间的联系,需要对应用进行注册。<br>修改settings.py中的INSTALLED_APPS配置项。</p>
<h3 id="启动项目"><a href="#启动项目" class="headerlink" title="启动项目"></a>启动项目</h3><p>运行开发web服务器命令:<br> python manage.py runserver</p>
<h2 id="模型类"><a href="#模型类" class="headerlink" title="模型类"></a>模型类</h2><h3 id="模型类生成表"><a href="#模型类生成表" class="headerlink" title="模型类生成表"></a>模型类生成表</h3><p>1) 生成迁移文件<br>命令:python manage.py makemigrations<br>2) 执行迁移生成表<br>命令:python mange.py migrate<br>根据迁移文件生成表。<br>生成表名的默认格式:<br>应用名_模型类名小写</p>
<h3 id="通过模型类操作数据表"><a href="#通过模型类操作数据表" class="headerlink" title="通过模型类操作数据表"></a>通过模型类操作数据表</h3><p>进入项目shell的命令:<br> python manage.py shell<br>首先导入模型类:<br> from booktest.models import BookInfo,HeroInfo<br>1) 向booktest_bookinfo表中插入一条数据。<br> b = BookInfo() #定义一个BookInfo类的对象<br> b.btitle =’天龙八部’ #定义b对象的属性并赋值<br> b.bpub_date = date(1990,10,11)<br> b.save() #才会将数据保存进数据库<br>2) 查询出booktest_bookinfo表中id为1的数据。<br> b = BookInfo.objects.get(id=1)<br>3) 在上一步的基础上改变b对应图书的出版日期。<br> b.bpub_date = date(1989,10,21)<br> b.save() #才会更新表格中的数据<br>4) 紧接上一步,删除b对应的图书的数据。<br> b.delete() #才会删除<br>5) 向booktest_heroInfo表中插入一条数据。<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">h = HeroInfo()</span><br><span class="line">h.hname = <span class="string">'郭靖'</span></span><br><span class="line">h.hgender = <span class="literal">False</span></span><br><span class="line">h.hcomment = ‘降龙十八掌’</span><br><span class="line">b2 = BookInfo.objects.get(id=<span class="number">2</span>)</span><br><span class="line">h.hbook = b2 <span class="comment">#给关系属性赋值,英雄对象所属的图书对象</span></span><br><span class="line">h.save()</span><br></pre></td></tr></table></figure></p>
<p>6) 查询图书表里面的所有内容。<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">BookInfo.objects.all()</span><br><span class="line">HeroInfo.objects.all()</span><br></pre></td></tr></table></figure></p>
<h3 id="关联操作"><a href="#关联操作" class="headerlink" title="关联操作"></a>关联操作</h3><p>1) 查询出id为2的图书中所有英雄人物的信息。<br> b = BookInfo.objects.get(id=2)<br> b.heroinfo_set.all() #查询出b图书中所有英雄人物的信息,其中heroinfo为英雄类的小写</p>
<h2 id="后台管理"><a href="#后台管理" class="headerlink" title="后台管理"></a>后台管理</h2><h3 id="管理界面本地化"><a href="#管理界面本地化" class="headerlink" title="管理界面本地化"></a>管理界面本地化</h3><p>可以通过通过定义应用下的models.py里面的数据表类的魔法方法(__srt__)来定义类的返回值,即在界面中的使用效果<br>本地化是将显示的语言、时间等使用本地的习惯,这里的本地化就是进行中国化,中国大陆地区使用简体中文,时区使用亚洲/上海时区,注意这里不使用北京时区表示。</p>
<p>打开test1/settings.py文件,找到语言编码、时区的设置项,将内容改为如下:</p>
<p>LANGUAGE_CODE = ‘zh-hans’ #使用中国语言<br>TIME_ZONE = ‘Asia/Shanghai’ #使用中国上海时间</p>
<h3 id="创建管理员"><a href="#创建管理员" class="headerlink" title="创建管理员"></a>创建管理员</h3><p>创建管理员的命令如下,按提示输入用户名、邮箱、密码。</p>
<p>python manage.py createsuperuser</p>
<h3 id="注册模型类"><a href="#注册模型类" class="headerlink" title="注册模型类"></a>注册模型类</h3><p>登录后台管理后,默认没有我们创建的应用中定义的模型类,需要在自己应用中的admin.py文件中注册,才可以在后台管理中看到,并进行增删改查操作。</p>
<p>打开booktest/admin.py文件,编写如下代码:<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> django.contrib <span class="keyword">import</span> admin</span><br><span class="line"><span class="keyword">from</span> booktest.models <span class="keyword">import</span> BookInfo,HeroInfo</span><br></pre></td></tr></table></figure></p>
<p>admin.site.register(BookInfo)<br>admin.site.register(HeroInfo)</p>
<h3 id="自定义管理页面"><a href="#自定义管理页面" class="headerlink" title="自定义管理页面"></a>自定义管理页面</h3><p>在列表页只显示出了BookInfo object,对象的其它属性并没有列出来,查看非常不方便。 Django提供了自定义管理页面的功能,比如列表页要显示哪些值。</p>
<p>打开booktest/admin.py文件,自定义类,继承自admin.ModelAdmin类。</p>
<p>属性list_display表示要显示哪些属性<br>class BookInfoAdmin(admin.ModelAdmin):<br> list_display = [‘id’, ‘btitle’, ‘bpub_date’]<br>修改1模型类BookInfo的注册代码如下<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">admin.site.register(BookInfo, BookInfoAdmin)</span><br></pre></td></tr></table></figure></p>
<h2 id="视图"><a href="#视图" class="headerlink" title="视图"></a>视图</h2><h3 id="定义视图"><a href="#定义视图" class="headerlink" title="定义视图"></a>定义视图</h3><p>视图就是一个Python函数,被定义在views.py中。</p>
<p>视图的必须有一个参数,一般叫request,视图必须返回HttpResponse对象,HttpResponse中的参数内容会显示在浏览器的页面上。</p>
<p>打开booktest/views.py文件,定义视图index如下<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> django.http <span class="keyword">import</span> HttpResponse</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">index</span><span class="params">(request)</span>:</span></span><br><span class="line"> <span class="keyword">return</span> HttpResponse(<span class="string">"index"</span>)</span><br></pre></td></tr></table></figure></p>
<p>2.配置URLconf<br>查找视图的过程<br>请求者在浏览器地址栏中输入url,请求到网站后,获取url信息,然后与编写好的URLconf逐条匹配,如果匹配成功则调用对应的视图函数,如果所有的URLconf都没有匹配成功,则返回404错误。</p>
<p>一条URLconf包括url规则、视图两部分:</p>
<p>url规则使用正则表达式定义。<br>视图就是在views.py中定义的视图函数。<br>需要两步完成URLconf配置:</p>
<p>1.在应用中定义URLconf<br>2.包含到项目的URLconf中<br>在booktest/应用下创建urls.py文件,定义代码如下:<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">from</span> django.conf.urls <span class="keyword">import</span> url</span><br><span class="line"><span class="keyword">from</span> booktest <span class="keyword">import</span> views</span><br><span class="line">urlpatterns = [</span><br><span class="line"> url(<span class="string">r'^$'</span>, views.index),</span><br><span class="line">]</span><br><span class="line">包含到项目中:打开test1/urls.py文件,为urlpatterns列表增加项如下:</span><br><span class="line"></span><br><span class="line">url(<span class="string">r'^'</span>, include(<span class="string">'booktest.urls'</span>)),</span><br><span class="line">test1/urls.py文件完整代码如下:</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> django.conf.urls <span class="keyword">import</span> include, url</span><br><span class="line"><span class="keyword">from</span> django.contrib <span class="keyword">import</span> admin</span><br><span class="line"></span><br><span class="line">urlpatterns = [</span><br><span class="line"> url(<span class="string">r'^admin/'</span>, include(admin.site.urls)),</span><br><span class="line"> url(<span class="string">r'^'</span>, include(<span class="string">'booktest.urls'</span>)),</span><br><span class="line">]</span><br></pre></td></tr></table></figure></p>
<h2 id="模板"><a href="#模板" class="headerlink" title="模板"></a>模板</h2><h3 id="创建模板"><a href="#创建模板" class="headerlink" title="创建模板"></a>创建模板</h3><p>为应用booktest下的视图index创建模板index.html,目录结构如下图:<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">.</span><br><span class="line">├── booktest</span><br><span class="line">│ ├── admin.py</span><br><span class="line">│ ├── __init__.py</span><br><span class="line">│ ├── migrations</span><br><span class="line">│ │ ├── 0001_initial.py</span><br><span class="line">│ │ ├── 0002_hero.py</span><br><span class="line">│ │ ├── __init__.py</span><br><span class="line">│ │ └── __pycache__</span><br><span class="line">│ │ ├── 0001_initial.cpython-36.pyc</span><br><span class="line">│ │ ├── 0002_hero.cpython-36.pyc</span><br><span class="line">│ │ └── __init__.cpython-36.pyc</span><br><span class="line">│ ├── models.py</span><br><span class="line">│ ├── __pycache__</span><br><span class="line">│ │ ├── admin.cpython-36.pyc</span><br><span class="line">│ │ ├── __init__.cpython-36.pyc</span><br><span class="line">│ │ ├── models.cpython-36.pyc</span><br><span class="line">│ │ ├── urls.cpython-36.pyc</span><br><span class="line">│ │ └── views.cpython-36.pyc</span><br><span class="line">│ ├── tests.py</span><br><span class="line">│ ├── urls.py</span><br><span class="line">│ └── views.py</span><br><span class="line">├── db.sqlite3</span><br><span class="line">├── manage.py</span><br><span class="line">├── templates</span><br><span class="line">│ └── booktest</span><br><span class="line">│ └── index.html</span><br><span class="line">└── test1</span><br><span class="line"> ├── __init__.py</span><br><span class="line"> ├── __pycache__</span><br><span class="line"> │ ├── __init__.cpython-36.pyc</span><br><span class="line"> │ ├── settings.cpython-36.pyc</span><br><span class="line"> │ ├── urls.cpython-36.pyc</span><br><span class="line"> │ └── wsgi.cpython-36.pyc</span><br><span class="line"> ├── settings.py</span><br><span class="line"> ├── urls.py</span><br><span class="line"> └── wsgi.py</span><br></pre></td></tr></table></figure></p>
<p>设置查找模板的路径:打开test1/settings.py文件,设置TEMPLATES的DIRS值<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">'DIRS'</span>: [os.path.join(BASE_DIR, <span class="string">'templates'</span>)],</span><br></pre></td></tr></table></figure></p>
<h3 id="定义模板"><a href="#定义模板" class="headerlink" title="定义模板"></a>定义模板</h3><p>打开templtes/booktest/index.html文件,定义代码如下:<br><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag"><<span class="name">html</span>></span></span><br><span class="line"><span class="tag"><<span class="name">head</span>></span></span><br><span class="line"> <span class="tag"><<span class="name">title</span>></span>图书列表<span class="tag"></<span class="name">title</span>></span></span><br><span class="line"><span class="tag"></<span class="name">head</span>></span></span><br><span class="line"><span class="tag"><<span class="name">body</span>></span></span><br><span class="line"><span class="tag"><<span class="name">h1</span>></span>{{title}}<span class="tag"></<span class="name">h1</span>></span></span><br><span class="line">{%for i in list%}</span><br><span class="line">{{i}}<span class="tag"><<span class="name">br</span>></span></span><br><span class="line">{%endfor%}</span><br><span class="line"><span class="tag"></<span class="name">body</span>></span></span><br><span class="line"><span class="tag"></<span class="name">html</span>></span></span><br></pre></td></tr></table></figure></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在模板中输出变量语法如下,变量可能是从视图中传递过来的,也可能是在模板中定义的。</span></span><br><span class="line"></span><br><span class="line">{{变量名}}</span><br><span class="line"><span class="comment">#在模板中编写代码段语法如下:</span></span><br><span class="line"></span><br><span class="line">{%代码段%}</span><br><span class="line">``` </span><br><span class="line"><span class="comment">### 视图调用模板</span></span><br><span class="line">调用模板分为三步骤:</span><br><span class="line"></span><br><span class="line"><span class="number">1.</span>找到模板</span><br><span class="line"><span class="number">2.</span>定义上下文</span><br><span class="line"><span class="number">3.</span>渲染模板</span><br><span class="line">打开booktst/views.py文件,调用上面定义的模板文件</span><br><span class="line">``` python</span><br><span class="line"><span class="keyword">from</span> django.http <span class="keyword">import</span> HttpResponse</span><br><span class="line"><span class="keyword">from</span> django.template <span class="keyword">import</span> loader,RequestContext</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">index</span><span class="params">(request)</span>:</span></span><br><span class="line"> <span class="comment"># 1.获取模板</span></span><br><span class="line"> template=loader.get_template(<span class="string">'booktest/index.html'</span>)</span><br><span class="line"> <span class="comment"># 2.定义上下文</span></span><br><span class="line"> context=RequestContext(request,{<span class="string">'title'</span>:<span class="string">'图书列表'</span>,<span class="string">'list'</span>:range(<span class="number">10</span>)})</span><br><span class="line"> <span class="comment"># 3.渲染模板</span></span><br><span class="line"> <span class="keyword">return</span> HttpResponse(template.render(context))</span><br></pre></td></tr></table></figure>
<h3 id="视图调用模板简写"><a href="#视图调用模板简写" class="headerlink" title="视图调用模板简写"></a>视图调用模板简写</h3><p>视图调用模板都要执行以上三部分,于是Django提供了一个函数render封装了以上代码。 方法render包含3个参数:</p>
<p>第一个参数为request对象<br>第二个参数为模板文件路径<br>第三个参数为字典,表示向模板中传递的上下文数据<br>打开booktst/views.py文件,调用render的代码如下:<br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> django.shortcuts <span class="keyword">import</span> render</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">index</span><span class="params">(request)</span>:</span></span><br><span class="line"> context={<span class="string">'title'</span>:<span class="string">'图书列表'</span>,<span class="string">'list'</span>:range(<span class="number">10</span>)}</span><br><span class="line"> <span class="keyword">return</span> render(request,<span class="string">'booktest/index.html'</span>,context)</span><br></pre></td></tr></table></figure></p>
<h1 id="Model属性及后端配置"><a href="#Model属性及后端配置" class="headerlink" title="Model属性及后端配置"></a>Model属性及后端配置</h1>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/03/30/Ubuntu/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Cedar Chen">
<meta itemprop="description" content>
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="blog">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/03/30/Ubuntu/" itemprop="url">Ubuntu</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Post created" itemprop="dateCreated datePublished" datetime="2019-03-30T23:57:06+08:00">
2019-03-30
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="Ubuntu软件操作的相关命令"><a href="#Ubuntu软件操作的相关命令" class="headerlink" title="Ubuntu软件操作的相关命令"></a>Ubuntu软件操作的相关命令</h1><p>sudo apt-get update 更新源</p>
<p>sudo apt-get install package 安装包</p>
<p>sudo apt-get remove package 删除包</p>
<p>sudo apt-cache search package 搜索软件包</p>
<p>sudo apt-cache show package 获取包的相关信息,如说明、大小、版本等</p>
<p>sudo apt-get install package –reinstall 重新安装包</p>
<p>sudo apt-get -f install 修复安装</p>
<p>sudo apt-get remove package –purge 删除包,包括配置文件等</p>
<p>sudo apt-get build-dep package 安装相关的编译环境</p>
<p>sudo apt-get upgrade 更新已安装的包</p>
<p>sudo apt-get dist-upgrade 升级系统</p>
<p>sudo apt-cache depends package 了解使用该包依赖那些包</p>
<p>sudo apt-cache rdepends package 查看该包被哪些包依赖</p>
<p>sudo apt-get source package 下载该包的源代码</p>
<p>sudo apt-get clean && sudo apt-get autoclean 清理无用的包</p>
<p>sudo apt-get check 检查是否有损坏的依赖</p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/03/25/mini-web/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Cedar Chen">
<meta itemprop="description" content>
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="blog">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/03/25/mini-web/" itemprop="url">mini-web</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Post created" itemprop="dateCreated datePublished" datetime="2019-03-25T11:32:57+08:00">
2019-03-25
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="WSGI-mini-web框架-finally"><a href="#WSGI-mini-web框架-finally" class="headerlink" title="WSGI-mini-web框架-finally"></a>WSGI-mini-web框架-finally</h1><p><strong> web_server.py </strong><br><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">```</span><br><span class="line"></span><br><span class="line">** mini_frame.py ** </span><br><span class="line">``` python</span><br></pre></td></tr></table></figure></p>
<p><a href="https://github.com/CedarChennn/mini_frame" target="_blank" rel="noopener">https://github.com/CedarChennn/mini_frame</a></p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/03/22/mySQL数据库/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Cedar Chen">
<meta itemprop="description" content>
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="blog">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/03/22/mySQL数据库/" itemprop="url">mySQL数据库</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Post created" itemprop="dateCreated datePublished" datetime="2019-03-22T17:29:08+08:00">
2019-03-22
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="数据库的基本使用"><a href="#数据库的基本使用" class="headerlink" title="数据库的基本使用"></a>数据库的基本使用</h1><p> sudo -s 切换到root用户<br> sudo service mysql start 启动MySQL<br> drop database <code>python-04</code>;<br> 其中`在table键上面<br> select database() 查看当前使用的数据库<br> desc 表名; 查看这个表的结构</p>
<h1 id="MySQL查询"><a href="#MySQL查询" class="headerlink" title="MySQL查询"></a>MySQL查询</h1><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">--修改表-修改字段-:重命名版</span></span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名 <span class="keyword">change</span> 旧列名 新列名 类型及约束;</span><br><span class="line"><span class="comment">--修改表-修改字段-:不重命名版</span></span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名 <span class="keyword">modify</span> 列名 类型及约束;</span><br><span class="line"></span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> students(</span><br><span class="line"><span class="keyword">id</span> <span class="built_in">int</span> <span class="keyword">unsigned</span> <span class="keyword">not</span> <span class="literal">null</span> primary <span class="keyword">key</span> auto_increment,</span><br><span class="line"><span class="keyword">name</span> <span class="built_in">varchar</span>(<span class="number">30</span>),</span><br><span class="line">age <span class="built_in">tinyint</span>(<span class="number">3</span>) <span class="keyword">unsigned</span> <span class="keyword">default</span> <span class="number">0</span>,</span><br><span class="line">heih <span class="built_in">decimal</span>(<span class="number">5</span>,<span class="number">2</span>),</span><br><span class="line">gender enum(<span class="string">'male'</span>,<span class="string">'female'</span>,<span class="string">'midle'</span>,<span class="string">'secret'</span>) <span class="keyword">default</span> <span class="string">'secret'</span>,</span><br><span class="line">cls_id <span class="built_in">int</span>(<span class="number">10</span>) <span class="keyword">unsigned</span></span><br><span class="line">);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> students <span class="keyword">values</span>(<span class="number">03</span>,<span class="string">"尼玛"</span>,<span class="number">122</span>,<span class="number">77.77</span>,<span class="string">"male"</span>,<span class="number">22</span>);</span><br><span class="line"><span class="comment">--插入值中如果自动递增可以用0,null,defaul占位</span></span><br><span class="line"><span class="comment">--插入enum时可用数字来代替枚举变量里面的值.枚举中的下表从1开始</span></span><br><span class="line"><span class="comment">--连续插入两个数据</span></span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> students <span class="keyword">values</span>(<span class="number">03</span>,<span class="string">"尼玛"</span>,<span class="number">122</span>,<span class="number">77.77</span>,<span class="string">"male"</span>,<span class="number">22</span>),(<span class="number">03</span>,<span class="string">"草尼玛"</span>,<span class="number">122</span>,<span class="number">77.77</span>,<span class="string">"male"</span>,<span class="number">22</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> students (<span class="keyword">name</span>,gender) <span class="keyword">values</span>(<span class="string">"quit"</span>,<span class="number">1</span>),(<span class="string">"exit"</span>,<span class="number">2</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">--数据库的准备</span></span><br><span class="line"> <span class="comment">--创建书数据库</span></span><br><span class="line"> <span class="keyword">create</span> <span class="keyword">database</span> python_test <span class="keyword">charset</span> = utf8;</span><br><span class="line"> <span class="comment">--使用数据库</span></span><br><span class="line"> <span class="keyword">use</span> python_test;</span><br><span class="line"> <span class="comment">--显示当前使用的数据库</span></span><br><span class="line"> <span class="keyword">select</span> <span class="keyword">database</span>();</span><br><span class="line"> <span class="comment">--创建一个表</span></span><br><span class="line"> <span class="keyword">create</span> <span class="keyword">table</span> students(</span><br><span class="line"> <span class="keyword">id</span> <span class="built_in">int</span> <span class="keyword">unsigned</span> primary <span class="keyword">key</span> auto_increment <span class="keyword">not</span> <span class="literal">null</span>,</span><br><span class="line"> <span class="keyword">name</span> <span class="built_in">varchar</span>(<span class="number">20</span>) <span class="keyword">default</span> <span class="string">''</span>,</span><br><span class="line"> age <span class="built_in">tinyint</span> <span class="keyword">unsigned</span> <span class="keyword">default</span> <span class="string">'0'</span>, </span><br><span class="line"> height <span class="built_in">decimal</span>(<span class="number">5</span>,<span class="number">2</span>),</span><br><span class="line"> gender enum(<span class="string">"male"</span>,<span class="string">"female"</span>,<span class="string">"midle"</span>,<span class="string">"unknow"</span>)<span class="keyword">default</span> <span class="string">"unknow"</span>,</span><br><span class="line"> cls_id <span class="built_in">int</span> <span class="keyword">unsigned</span> <span class="keyword">default</span> <span class="string">'0'</span>,</span><br><span class="line"> is_delete <span class="built_in">bit</span> <span class="keyword">default</span> <span class="number">0</span></span><br><span class="line"> );</span><br><span class="line"> <span class="keyword">create</span> <span class="keyword">table</span> classes(</span><br><span class="line"> <span class="keyword">id</span> <span class="built_in">int</span> <span class="keyword">unsigned</span> auto_increment primary <span class="keyword">key</span> <span class="keyword">not</span> <span class="literal">null</span>,</span><br><span class="line"> <span class="keyword">name</span> <span class="built_in">varchar</span>(<span class="number">30</span>) <span class="keyword">not</span> <span class="literal">null</span></span><br><span class="line"> );</span><br><span class="line"> <span class="keyword">insert</span> <span class="keyword">into</span> students <span class="keyword">values</span></span><br><span class="line"> (<span class="number">0</span>,<span class="string">"tom"</span>,<span class="number">18</span>,<span class="number">173.22</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">1</span>),</span><br><span class="line"> (<span class="number">0</span>,<span class="string">"midle"</span>,<span class="number">15</span>,<span class="number">173.22</span>,<span class="number">2</span>,<span class="number">2</span>,<span class="number">0</span>),</span><br><span class="line"> (<span class="number">0</span>,<span class="string">"apple"</span>,<span class="number">13</span>,<span class="number">173.22</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">0</span>),</span><br><span class="line"> (<span class="number">0</span>,<span class="string">"hard"</span>,<span class="number">33</span>,<span class="number">173.22</span>,<span class="number">2</span>,<span class="number">1</span>,<span class="number">0</span>),</span><br><span class="line"> (<span class="number">0</span>,<span class="string">"micro"</span>,<span class="number">56</span>,<span class="number">173.22</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">0</span>),</span><br><span class="line"> (<span class="number">0</span>,<span class="string">"goole"</span>,<span class="number">93</span>,<span class="number">173.22</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">0</span>),</span><br><span class="line"> (<span class="number">0</span>,<span class="string">"amazon"</span>,<span class="number">34</span>,<span class="number">173.22</span>,<span class="number">2</span>,<span class="number">1</span>,<span class="number">0</span>),</span><br><span class="line"> (<span class="number">0</span>,<span class="string">"bing"</span>,<span class="number">154</span>,<span class="number">173.22</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">0</span></span><br><span class="line"> <span class="keyword">insert</span> <span class="keyword">into</span> classes <span class="keyword">values</span></span><br><span class="line"> (<span class="number">0</span>,<span class="string">"python"</span>),</span><br><span class="line"> (<span class="number">1</span>,<span class="string">"c++"</span>),</span><br><span class="line"> (<span class="number">2</span>,<span class="string">"MySQL"</span>);</span><br><span class="line"> <span class="comment">--去重查询</span></span><br><span class="line"> <span class="keyword">select</span> <span class="keyword">distinct</span> gender <span class="keyword">from</span> students;</span><br><span class="line"> <span class="comment">--模糊查询</span></span><br><span class="line"> <span class="comment">--like</span></span><br><span class="line"> <span class="comment">--% 替换1个或者多个 </span></span><br><span class="line"> <span class="comment">--_替换一个头</span></span><br><span class="line"> <span class="comment">--查询姓名中所有"小"的所有名字</span></span><br><span class="line"> <span class="keyword">select</span> * <span class="keyword">from</span> students <span class="keyword">where</span> <span class="keyword">name</span> <span class="keyword">like</span><span class="string">"%小%"</span>;</span><br><span class="line"> <span class="comment">--查询至少有两个字的字的名字</span></span><br><span class="line"> <span class="keyword">select</span> * <span class="keyword">from</span> students <span class="keyword">where</span> <span class="keyword">name</span> <span class="keyword">like</span> <span class="string">"__%"</span>;</span><br><span class="line"> <span class="comment">--rlike 正则表达式匹配</span></span><br><span class="line"> <span class="comment">--查询以周开始的名字</span></span><br><span class="line"> <span class="keyword">select</span> * <span class="keyword">from</span> students <span class="keyword">where</span> <span class="keyword">name</span> <span class="keyword">rlike</span> <span class="string">"^m.*"</span>;</span><br><span class="line"> <span class="comment">--周开始伦结尾</span></span><br><span class="line"> <span class="keyword">select</span> * <span class="keyword">from</span> students <span class="keyword">where</span> <span class="keyword">name</span> <span class="keyword">rlike</span> <span class="string">"^周.*伦$"</span>;</span><br><span class="line"> <span class="comment">--范围查询</span></span><br><span class="line"> <span class="keyword">select</span> * <span class="keyword">from</span> students <span class="keyword">where</span> age <span class="keyword">in</span> (<span class="number">18</span>,<span class="number">13</span>);</span><br><span class="line"> <span class="keyword">select</span> * <span class="keyword">from</span> students <span class="keyword">where</span> age <span class="keyword">between</span> <span class="number">18</span> <span class="keyword">and</span> <span class="number">100</span>;</span><br><span class="line"></span><br><span class="line"> <span class="comment">--保留两位小数</span></span><br><span class="line"> <span class="keyword">select</span> <span class="keyword">round</span>(<span class="keyword">avg</span>(age)* <span class="keyword">count</span>(age),<span class="number">2</span>) <span class="keyword">from</span> students;</span><br><span class="line"> <span class="comment">--分组</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">--查看组内的内容</span></span><br><span class="line"> <span class="keyword">select</span> gender,<span class="keyword">group_concat</span>(<span class="keyword">name</span>) <span class="keyword">from</span> students <span class="keyword">group</span> <span class="keyword">by</span> gender;</span><br><span class="line"> <span class="comment">--查询每种性别中人数多于2个的信息</span></span><br><span class="line"> <span class="keyword">select</span> gender ,<span class="keyword">group_concat</span>(<span class="keyword">name</span>) <span class="keyword">from</span> students <span class="keyword">group</span> <span class="keyword">by</span> gender <span class="keyword">having</span> <span class="keyword">count</span>(gender)><span class="number">2</span>;</span><br><span class="line"> <span class="comment">--限制查询出的数据的个数</span></span><br><span class="line"> <span class="keyword">select</span> * <span class="keyword">from</span> students <span class="keyword">where</span> gender =<span class="number">1</span> <span class="keyword">limit</span> <span class="number">0</span>,<span class="number">5</span>;<span class="comment">--limit(第N页-1)*每页的个数,每页的个数</span></span><br><span class="line"> <span class="comment">--连接查询</span></span><br><span class="line"> <span class="keyword">select</span> students.name,classes.name <span class="keyword">from</span> students ,classes <span class="keyword">where</span> classes.id =students.cls_id;</span><br><span class="line"> <span class="comment">--内连接</span></span><br><span class="line"> <span class="keyword">select</span> students.*,classes.name <span class="keyword">from</span> students <span class="keyword">inner</span> <span class="keyword">join</span> classes <span class="keyword">on</span> students.cls_id =classes.id;</span><br><span class="line"> <span class="keyword">select</span> c.name ,s.name <span class="keyword">from</span> classes <span class="keyword">as</span> c <span class="keyword">inner</span> <span class="keyword">join</span> students <span class="keyword">as</span> s <span class="keyword">on</span> c.id = s.cls_id <span class="keyword">order</span> <span class="keyword">by</span> c.name;</span><br><span class="line"> <span class="comment">--子查询</span></span><br><span class="line"></span><br><span class="line"><span class="comment">--创建京豆数据库</span></span><br><span class="line"><span class="keyword">create</span> <span class="keyword">database</span> jing_dong <span class="keyword">charset</span> = utf8;</span><br><span class="line"><span class="comment">--使用京东数据可</span></span><br><span class="line"><span class="keyword">use</span> jing_dong;</span><br><span class="line"><span class="comment">--创建一个商品goods数据表</span></span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> goods(</span><br><span class="line"> <span class="keyword">id</span> <span class="built_in">int</span> <span class="keyword">unsigned</span> primary <span class="keyword">key</span> auto_increment <span class="keyword">not</span> <span class="literal">null</span>,</span><br><span class="line"> <span class="keyword">name</span> <span class="built_in">varchar</span>(<span class="number">150</span>) <span class="keyword">not</span> <span class="literal">null</span>,</span><br><span class="line"> cate_name <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">not</span> <span class="literal">null</span>,</span><br><span class="line"> brand_name <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">not</span> <span class="literal">null</span>,</span><br><span class="line"> price <span class="built_in">decimal</span>(<span class="number">10</span>,<span class="number">3</span>) <span class="keyword">not</span> <span class="literal">null</span> <span class="keyword">default</span> <span class="number">0</span>,</span><br><span class="line"> is_show <span class="built_in">bit</span> <span class="keyword">not</span> <span class="literal">null</span> <span class="keyword">default</span> <span class="number">1</span>,</span><br><span class="line"> is_saleoff <span class="built_in">bit</span> <span class="keyword">not</span> <span class="literal">null</span> <span class="keyword">default</span> <span class="number">0</span></span><br><span class="line">);</span><br><span class="line"><span class="comment">--向good表中插入数据</span></span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'r510 15.6寸笔记本电脑'</span>,<span class="string">'笔记本'</span>,<span class="string">'华硕'</span>,<span class="string">'3399'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'r510 14.6寸笔记本电脑'</span>,<span class="string">'笔记本'</span>,<span class="string">'联想'</span>,<span class="string">'4999'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'r150h 15.6寸游戏本'</span>,<span class="string">'游戏本'</span>,<span class="string">'雷神'</span>,<span class="string">'8499'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'r550cc 15.6寸笔记本电脑'</span>,<span class="string">'笔记本'</span>,<span class="string">'华硕'</span>,<span class="string">'2799'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'r240 超极本'</span>,<span class="string">'超极本'</span>,<span class="string">'联想'</span>,<span class="string">'4299'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'r13226scb 超级触控笔记本'</span>,<span class="string">'超极本'</span>,<span class="string">'索尼'</span>,<span class="string">'7999'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'ipad mini 7.9英寸平板电脑'</span>,<span class="string">'平板电脑'</span>,<span class="string">'苹果'</span>,<span class="string">'1998'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'ipad mini 9.7英寸平板电脑'</span>,<span class="string">'平板电脑'</span>,<span class="string">'苹果'</span>,<span class="string">'2799'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'ipad mini配备retina显示屏幕'</span>,<span class="string">'平板电脑'</span>,<span class="string">'苹果'</span>,<span class="string">'2788'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'20英寸一体电脑'</span>,<span class="string">'台式机'</span>,<span class="string">'戴尔'</span>,<span class="string">'2899'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'imac21.5寸一体电脑'</span>,<span class="string">'台式机'</span>,<span class="string">'苹果'</span>,<span class="string">'9188'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'台式电脑linux'</span>,<span class="string">'台式机'</span>,<span class="string">'宏碁'</span>,<span class="string">'3699'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'r510 工作站'</span>,<span class="string">'服务器/工作站'</span>,<span class="string">'惠普'</span>,<span class="string">'4288'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'ii服务器'</span>,<span class="string">'服务器/工作站'</span>,<span class="string">'戴尔'</span>,<span class="string">'5388'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'mac pro专业台式电脑'</span>,<span class="string">'服务器工作站'</span>,<span class="string">'苹果'</span>,<span class="string">'28888'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'头戴显示设备'</span>,<span class="string">'笔记本配件'</span>,<span class="string">'索尼'</span>,<span class="string">'6999'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'商务双肩背包'</span>,<span class="string">'笔记本配件'</span>,<span class="string">'索尼'</span>,<span class="string">'99'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'m4机构式服务器'</span>,<span class="string">'服务器/工作站'</span>,<span class="string">'ibm'</span>,<span class="string">'6888'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'商务双肩背包'</span>,<span class="string">'笔记本配件'</span>,<span class="string">'索尼'</span>,<span class="string">'99'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'X240 超极本'</span>,<span class="string">'超级本'</span>,<span class="string">'联想'</span>,<span class="string">'4880'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'ipad air 9.7英寸平板电脑'</span>,<span class="string">'平板电脑'</span>,<span class="string">'苹果'</span>,<span class="string">'3388'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods <span class="keyword">values</span>(<span class="number">0</span>,<span class="string">'c340 20英寸一体电脑'</span>,<span class="string">'台式机'</span>,<span class="string">'联想'</span>,<span class="string">'3499'</span>,<span class="keyword">default</span>,<span class="keyword">default</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">select</span> <span class="keyword">name</span> price <span class="keyword">from</span> goods <span class="keyword">where</span> cate_name=<span class="string">'超极本'</span>;</span><br><span class="line"><span class="keyword">update</span> goods <span class="keyword">set</span> cate_name =<span class="string">'超极本'</span> <span class="keyword">where</span> <span class="keyword">id</span> = <span class="number">20</span>;</span><br><span class="line"><span class="keyword">select</span> <span class="keyword">distinct</span> cate_name <span class="keyword">from</span> goods <span class="keyword">group</span> <span class="keyword">by</span> cate_name;</span><br><span class="line"><span class="keyword">select</span> <span class="keyword">round</span>(<span class="keyword">avg</span>(price),<span class="number">2</span>) <span class="keyword">from</span> goods;</span><br><span class="line"><span class="keyword">select</span> cate_name,<span class="keyword">avg</span>(price) <span class="keyword">from</span> goods <span class="keyword">group</span> <span class="keyword">by</span> cate_name;</span><br><span class="line"><span class="keyword">select</span> * <span class="keyword">from</span> goods <span class="keyword">where</span> price></span><br><span class="line">(</span><br><span class="line"><span class="keyword">select</span> <span class="keyword">avg</span>(price) <span class="keyword">from</span> goods</span><br><span class="line">);</span><br><span class="line"><span class="comment">--查询每种商品中最贵的</span></span><br><span class="line"><span class="keyword">select</span> * <span class="keyword">from</span> goods <span class="keyword">as</span> <span class="keyword">old</span></span><br><span class="line"><span class="keyword">inner</span> <span class="keyword">join</span></span><br><span class="line">(</span><br><span class="line"><span class="keyword">select</span> cate_name,<span class="keyword">max</span>(price) <span class="keyword">as</span> maxprice </span><br><span class="line"><span class="keyword">from</span> goods</span><br><span class="line"><span class="keyword">group</span> <span class="keyword">by</span> cate_name</span><br><span class="line">)<span class="keyword">as</span> <span class="keyword">new</span></span><br><span class="line"><span class="keyword">on</span> old.cate_name=new.cate_name <span class="keyword">and</span> old.price = new.maxprice;</span><br><span class="line"><span class="comment">--建表</span></span><br><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> <span class="keyword">if</span> <span class="keyword">not</span> <span class="keyword">exists</span> goods_cates(</span><br><span class="line"> <span class="keyword">id</span> <span class="built_in">int</span> <span class="keyword">unsigned</span> primary <span class="keyword">key</span> auto_increment,</span><br><span class="line"> <span class="keyword">name</span> <span class="built_in">varchar</span>(<span class="number">40</span>) <span class="keyword">not</span> <span class="literal">null</span></span><br><span class="line">);</span><br><span class="line"></span><br><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> goods_cates (<span class="keyword">name</span>) <span class="keyword">select</span> <span class="keyword">distinct</span> cate_name <span class="keyword">from</span> goods; </span><br><span class="line"><span class="comment">--通过goods_cates表来更像goods表!!!!!重点!!!!!!!!!</span></span><br><span class="line"><span class="keyword">update</span> goods </span><br><span class="line"><span class="keyword">inner</span> <span class="keyword">join</span> goods_cates</span><br><span class="line"><span class="keyword">on</span> goods.cate_name = goods_cates.name</span><br><span class="line"><span class="keyword">set</span> goods.cate_name = goods.id;</span><br><span class="line"></span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> goods <span class="keyword">add</span> <span class="keyword">foreign</span> <span class="keyword">key</span>(cate_id) <span class="keyword">references</span> goods_cates(<span class="keyword">id</span>);</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> goods <span class="keyword">drop</span> <span class="keyword">foreign</span> <span class="keyword">key</span> 外键名;</span><br><span class="line"><span class="comment">--视图</span></span><br><span class="line"><span class="keyword">create</span> <span class="keyword">view</span> view_name <span class="keyword">as</span> <span class="keyword">select</span> * <span class="keyword">from</span> goods;</span><br><span class="line"></span><br><span class="line"><span class="comment">--事物四大特性-ACID</span></span><br><span class="line"> <span class="comment">--原子性atomicity</span></span><br><span class="line"> <span class="comment">--一致性consistency</span></span><br><span class="line"> <span class="comment">--隔离性isolation</span></span><br><span class="line"> <span class="comment">--开启事务 </span></span><br><span class="line"> <span class="keyword">begin</span>; <span class="comment">--或者 start transaction;</span></span><br><span class="line"> <span class="comment">--提交事务</span></span><br><span class="line"> <span class="keyword">commit</span>;</span><br><span class="line"> <span class="comment">--回滚事务</span></span><br><span class="line"> <span class="keyword">rollback</span>;</span><br><span class="line"> <span class="comment">--持久性durability</span></span><br><span class="line"><span class="comment">--索引 create index 索引名称 on 表名(字段名称(长度))</span></span><br><span class="line"><span class="keyword">create</span> <span class="keyword">index</span> goods_index <span class="keyword">on</span> goods(<span class="keyword">id</span>(<span class="number">10</span>));<span class="comment">--如果id类型是varchar或者char则括号里面的10是指他的长度,如果是int就不用写</span></span><br><span class="line"><span class="comment">--drop ondex 索引名称 on表名</span></span><br><span class="line"><span class="comment">--grant 权限列表 on 数据库 to '用户名'@'访问主机' identified by '密码';</span></span><br><span class="line"><span class="comment">--其中'数据库.*'表示给这个数据库的所有表对应的权限</span></span><br><span class="line"><span class="comment">--备份-运行mysqldump命令</span></span><br><span class="line">mysqldump -u root -p 数据库名 > XXX.sql;</span><br><span class="line">-恢复</span><br><span class="line"> <span class="comment">--首先连接MySQL ,创建新的数据库</span></span><br><span class="line"> <span class="comment">--退出连接,执行如下的命令</span></span><br><span class="line">mysql -u root -p 新数据名 < XXX.sq;</span><br></pre></td></tr></table></figure>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/03/20/python高级语法/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Cedar Chen">
<meta itemprop="description" content>
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="blog">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/03/20/python高级语法/" itemprop="url">python高级语法</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Post created" itemprop="dateCreated datePublished" datetime="2019-03-20T21:22:35+08:00">
2019-03-20
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="深拷贝和浅拷贝"><a href="#深拷贝和浅拷贝" class="headerlink" title="深拷贝和浅拷贝"></a>深拷贝和浅拷贝</h1><h1 id="私有化-封装继承-多态"><a href="#私有化-封装继承-多态" class="headerlink" title="私有化,封装继承,多态"></a>私有化,封装继承,多态</h1>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/03/19/web服务器/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="Cedar Chen">
<meta itemprop="description" content>
<meta itemprop="image" content="/images/avatar.gif">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="blog">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/03/19/web服务器/" itemprop="url">web服务器</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">Posted on</span>
<time title="Post created" itemprop="dateCreated datePublished" datetime="2019-03-19T15:10:13+08:00">
2019-03-19
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="正则表达式"><a href="#正则表达式" class="headerlink" title="正则表达式"></a>正则表达式</h1><h2 id="匹配单个字符"><a href="#匹配单个字符" class="headerlink" title="匹配单个字符"></a>匹配单个字符</h2><p>点.匹配任意一个字符<br>[ ] 匹配[ ]中列举的字符<br>\d 匹配数字,即0-9<br>\D 匹配非数字,即不是数字<br>\s 匹配空白,即空格,tab键<br>\S 匹配非空白<br>\w 匹配单词字符,即a-z、A-Z、0-9、_<br>\W 匹配非单词字符</p>
<h2 id="匹配多个字符"><a href="#匹配多个字符" class="headerlink" title="匹配多个字符*"></a>匹配多个字符*</h2><p>星号*匹配前一个字符出现0次或无限次,即可有可无<br>加号+ 匹配前一个字符出现1次或无限次,即至少有一次<br>? 匹配前一个字符出现一次或者0次,即要么没有要么一次<br>{m} 匹配前一个字符出现m次<br>{m,n} 匹配前一个字符出现m到n次</p>
<h2 id="匹配开头结尾"><a href="#匹配开头结尾" class="headerlink" title="匹配开头结尾"></a>匹配开头结尾</h2><p>^ 匹配字符开头<br>$ 匹配字符结尾</p>
<h2 id="匹配分组"><a href="#匹配分组" class="headerlink" title="匹配分组"></a>匹配分组</h2><p>| 匹配左右任意一个表达式<br>(ab) 将括号中字符作为一个组<br>\num 引用分组num匹配到字符串<br>(?p<name>) 分区起别名<br>(?p=name>) 引用别名为name分组匹配到的字符串</name></p>
<h1 id="简单的web服务器的实现"><a href="#简单的web服务器的实现" class="headerlink" title="简单的web服务器的实现"></a>简单的web服务器的实现</h1><h2 id="tcp三次握手、四次挥手"><a href="#tcp三次握手、四次挥手" class="headerlink" title="tcp三次握手、四次挥手"></a>tcp三次握手、四次挥手</h2><h3 id="三次握手"><a href="#三次握手" class="headerlink" title="三次握手"></a>三次握手</h3><p>所谓三次握手(Three-way Handshake),是指建立一个 TCP 连接时,需要客户端和服务器总共发送3个包。</p>