[TOC]
# 一.前端:
## 1.Html
### 1.1 常见标签
- div / span / a / img / table / form / ul / ol / li / strong / b / i / p /
- 行内:span / a / b / s / del / em / sup /sub /
- 块级:div / p / h1 / table / tr /th / td / ul /ol / li / dl /
- inline-block:img / button / input / lable / select / option /
### 1.2 input
```html
<input type="text" />
<input type="number" />
<input type="password" />
<input type="radio" name="" /> //单选框name要一致 <input type="button" /> //按钮
<input type="checkbox" /> //多选框
<input type="email" />
<input type="submit" />
```
## 2.Css
### 2.1 常见样式
```css
color:#...;//文本颜色
background-color;
line-height;
box-shadow;
font-family;
font-size;
font-weight;//字体粗细
text-align;
text-indent;//首行文本缩进
text-decoration:none;
//float:
clearfix,clearboth;
//伪类
a:link / visited / hover /active
//position: fixed / absolute /
z-index
```
### 2.2 引入 css
```html
<link style="stylesheet" href="" />
```
## 3.Javasctipt
### 3.1 引入 js
```html
<script></script>
```
### 3.2 常见类型和操作
```javascript
//1.字符串:
var name='hello'
var name=String('hello')
//常见操作
var v1=name.length;
var v2=name[0]//charAt(0)
var v3=name.trim()//'hello'
var v4=name.substring(1,2);//e
// 2.Array:
var a=[11,22];
//常见操作
// --加
a[0]='hello';
a.push('hello');//[11,22,'hello']
a.unshift('a');//['a',11,22]
a.splice(索引位置,0,元素);//0加,1减;
a.splice(1,0,'a');//[11,'a',22]
// --减
a.pop()
a.shift()
a.splice(2,1)//[11]
//循环
for(var item in a){
data=a[item]//11,22
}
// 3.dom创建:
var a=[11,22,33];
for(var idx in a){
var text = a [idx];
var tag=document.createElement('li');
tag.innerText=text;
var parentTag=document.gerElementById('numlist');
parenTag.appendChild(tag);
}
// 4.Dict字典(对象)
info={
name:"Alex",
age:11
}
delete info.age
for(var key in info){
data=info[key]
}
// 5.函数:
function f(){
...
}
(f(){
dosomething();
});
// 6.DOM:
var tag=window.document.getElementById('xx');
tag.innerText="hello"
/html
<input type='text' id='a'>
/js: var txt=document.getElementById('a');
var input=txt.value;
if(input.length>0)
{
var tag=window.document.getElementById('xx');
tag.innerText=input;
var parentTag=document.gerElementById('numlist');
parenTag.appendChild(tag);
input.value='';//clear the content;
}
else
{
alert('input none');
}
```
## 4.jquery
> $( # id) $(.class) $('h1')
```javascript
// 1.直接找
<p>lll</p>;
$("#test").text("hello");
$('.c1 .c2 a')
$('#id1,#id2')//多选择器
$('input[name='n1']')
// 2.间接寻找
$('#id1').perv()/next().next()/.../siblings()../
.parent()/.children()/.children('.class1')/
find('div').removeClass('hello')
// 3.样式:
addClass
removeClass
hasClass
remove()
// 4.值的操作
$("#test").text("hello");
/html:
$('#input').val()
$('#input').val("hahahh")//
5.创建标签$('<li>')
// 5.事件绑定
$('li').click(function(){
var text=$(this).text();//点这个标签
...
})
当页面框架加载完成在执行:
$(function(){
$('li').click(function(){
var text=$(this).text();//点这个标签
...
})
...
})
```
## 5.tempalte
> {{item}}
> {% for item in data_list %}
# 二.后端
## 1.Python
#### 1.1.编码:
```python
> ascll,gb2312(中文两个字节),unicode(ucs2/ucs4),utf-8(中文三个字节)
> 单位:
> 位/字节/kb/m/g/t;
```
#### 1.2.Python 字符串的格式化:
```js
var a="hello my name is {},come from us,{}".fomat("Alexmaodali","SanfSco);
var a="hello my name is%s,old:%d;"%("Alexmaodali",33);
```
#### 1.3.DataType
> int bool str list tuple dict set float None
```
False:None,空,0
可变:list,set,dict
字典的key和集合元素,必须是可哈希的DataType;
不可哈希:list,set,dict
```
#### 1.4.独有功能:
```
共有:len/index/切片/for/是否包含/join
-str:upper/lower/startwith,split/strip..
-list:append/insert/remove/pop...
-dict:get/keys/items/values...
```
#### 1.5.推导式
```
data=[i for i in range(10) if i < 5]
```
#### 1.6.函数:
```python
动态参数:*args,**kwargs;
无参数默认返回None
全局变量一般大写
局部变量小写下划线连接/global引用全局变量而不是局部变量;
1.内置函数
bin/hex/odc/max/open/divmod/sorted
2.文件操作
with open ...
-r/rb
-w/wb写(清空)/自动新建文件
-a/ab/追加/自动新建文件
文件夹不存在,报错
Address Above:
os.makedirs/os.path.exsits
```
#### 1.7.module
```
build-in-:time/datatime/json/re/random/os...
source:requests/openpyxl/bs4/flask/python-docx
self-build:os.path
1.查看文件:
os.listdir/os.walk
2.time
3.JSON:
无单引号/元组
序列化:JSON.dumps
4.re:
-\d \w
re.search/re.match/re.findall
贪婪,不贪婪加?
5.
pip
wheel
源码
```
#### 1.8.oop
> 封装,继承,多态
```
```
## 2.java
# 三 .数据库
## 1.Mysql(管理员打开 cmd)
synax:
```mysql
create table admin(
id int not null auto_increment primary key,
username varchar(16) not null,
password varchar(16) not null,
phone char(11) not null
) default charset=utf8;
```
1.1.Start services:
临时启动:
mysqld.exe
服务启动:
"D:\WorkingAbout\FrontedTools\MySQL\mysql-5.7.31-winx64\bin\mysqld.exe" --install mysql57
net start mysql57
net stop mysql57
"D:\WorkingAbout\FrontedTools\MySQL\mysql-5.7.31-winx64\bin\mysqld.exe" -h 127.0.0.1 -P 3306 -u -root -p
加入环境变量:
> mysql -u root -p
1.2.set password=password("root")
1.3.exit;
## 2.pymysql
> 新增,删除,修改一定要 connect.commit(),不然数据库没数据
### 2.1.插入 insert
```python
import pymysql
if __name__ == '__main__':
# 1.连接数据库
con = pymysql.connect(host="localhost", port=3306,
user='root', passwd='root', charset='utf8', db='unicom')
cursor = con.cursor(cursor=pymysql.cursors.DictCursor)
#2.执行SQL指令;
sql = "insert into admin(username,password,mobile) values(...)"
cursor.execute(sql)
con.commit()
#3.关闭连接;
cursor.close()
con.close()
```
### 2.2.选择 select
```python
import pymysql
if __name__ == '__main__':
# 1.连接数据库
con = pymysql.connect(host="localhost", port=3306,
user='root', passwd='root', charset='utf8', db='unicom')
cursor = con.cursor(cursor=pymysql.cursors.DictCursor)
#2.执行SQL指令;
sql = "select * from admin where id > %s"
cursor.execute(sql,[2,])
# con.commit()
# fetchone()
data_list=cursor.fetchall()
#3.关闭连接;
cursor.close()
con.close()
```
### 2.3.格式分组
```python
sql = "insert into admin(username,password,mobile) values(%(n1)s,%(n2)s,%(n3)s)"
cursor.execute(sql, {"n1": 'hello', "n2": "liek", "n3": "3333"})
con.commit()
```
# 四.开发框架
## 1.Flask:
dir:
```
└─static
├─css
├─img
├─js
│ └─jQuery-3.7
│
├─plugins
│ ├─bootstrap-3.4.1-dist
│
└─templates
|_index.html
|_demo.py
```
```python
from flask import Flask,render_template
app=Flask(__name__)
@app.route("/add/user")
def add_user():
# //in dir:templates
return render_template("add_user.html")
if __name__=='__main__':
app.run()
```
## 2.Django
### 2.1 安装
> pip install django
### 2.2 创建 django 项目
> django-admin startproject 项目名称
### 2.3 默认文件
```
mysite
|-- manage.py //项目管理,启动
|-- mysite
|-- __init__.py
|-- settings.py //项目配置文件
|-- urls.py //url和函数对应关系
|-- asgi.py //接收网络请求
|-- wsgi.py //接收网络请求
```
### 2.4 创建 app(功能)
> python manage.py startapp app 名
### 2.5 启动 django 项目
#### 2.5.1 注册 app
```
in INSTALLED_APPS 加 app名.apps.App名Config
```
#### 2.5.2 设置 urls
```python
urls:
from app名 import views
urlpattern=[
path('index/',views.index),
]
```
#### 2.5.3 写函数 view.py
```python
from django.shortcuts import render , HttpsResponse
def index(request):
return HttpsResponse("启动成功")
```
#### 2.5.4 启动
> python manage.py runserver
> localhost/index/
### 2.6 templates and static
> render(request,'index.html')
#### 2.6.1 templates 查找规则
> 默认去 app 名目录下的 templates 找(app 注册顺序)
```
> TEMPLATES=[
> 'DIRS':[os.path.join(BASE_DIR,'templates')],
> ]
上面存在则优先根目录[提前配置]
```
#### 2.6.2 static 静态文件
```
> app名 / static
> static / css , js , plugins , img ...
```
静态文件写法
```html
//load 这一行不要写在html最上面 //运行时要运行django项目而不是html文件 {% load
static %} <link rel="stylesheet" href="{% static 'plugins/...css' %}" />
```
### 2.7 模板语法
```python
取列表:
{{ n1.0/1 ... }}
render(request,'tpl.html',{"n1":name,"n2":data_list})
{% for item(k,v) in n2(.keys,.values) %}
<span>{{ item }}</span>
{% endfor %}
{% if n1 == "name" %}
...html...
{% elif n1 =="xxx" %}
...html...
```
```python
def user_info(request):
data_list=UserInfo.objects.all()
return render(request,"user_info.html",{"data_list":data_list})
```
### 2.8 请求与响应
```python
1.request请求:
-request.method
-request.GET 获取在url上传递值
-request.POST
2.HttpsResponse返回/响应
-1.HttpsResponse("xxx")
-2.读取html内容+渲染templates-->字符串,返回给浏览器用户:
-return render(request,'index.html',{"title":"ddd"})
-3重定向
return redirect("baudu.com")
e.g:
if request.method=="GET":
xxx;
if request.method=="POST":
username=request.POST.get("user",None)
#获取checkbox等多内容
username=request.POST.getlist("user",None)
<form xxx>
{% csrf_token %}
</form>
view.py:
from django.template.context_processors import csrf
......
```
### 2.9 django 连接 mysql
```python
> pip install mysqlclient(2.2.0)
```
#### 2.9.1 orm 创建数据库
mysql:
```mysql
create table admin(
id int not null auto_increment primary key,
username varchar(16) not null,
password varchar(16) not null,
phone char(11) not null
) default charset=utf8;
```
```
create table user(
id int not null auto_increment primary key,
username varchar(255) not null,
password varchar(255) not null,
) default charset=utf8;
```
orm:对表操作,但创建不了数据库
```
创建数据库:
create database databasename DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
```
django/settings:
```
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
#数据库名字
'NAME':'dbname',
'USER': 'root',
'PASSWORD': 'xxx',
'HOST': 'localhost',
'PORT': 3306,
}
}
```
### 2.9.2 django 操作表
```
models.py:
from django.db import models
# Create your models here.
class UserInfo(models.Model):
name=models.CharField(max_length=32)
password=models.CharField(max_length=32)
age=models.IntegerField()
"""
create table app名_类名小写
create table appapp01_userinfo(
id bigint auto_increment primary key,
name varchar(32),
password varchar(32),
);
"""
```
### 2.9.3 更新数据库表:
```
python manage.py makemigrations
python manage.py migrate
```
### 2.9.4 添加字段(列)
```python
class UserInfo(models.Model):
"""用户表"""
name = models.CharField(verbose_name="用户名", max_length=32)
password = models.CharField(max_length=32)
age = models.IntegerField()
age=models.IntegerField(default=2)
age1=models.IntegerField(null=True,blank=True)
```
对表结构进行操作只需对 models.py 中的类进行操作,再执行命令
### 2.9.5 操作表中的数据
#### 2.9.5.1 新增数据(可以写在 view.py 类里)
```
# 新增数据(可以写在view.py类里)
UserInfo.objects.create(name="alexmaodali",password="sss",age=12)
UserInfo.objects.filter(id=2).delete
UserInfo.objects.all().delete
#获取数据
data_list=UserInfo.objects.all()#queryset(list)
for obj in data_list:
print(obj.id,obj.name)
#获取一行
row_obj=UserInfo.objects.filter(id=2).first()
#更新数据
UserInfo.objects.filter(name='ssss').update(name="2222")
```
#### 2.9.5.2 绑定表/关联表
```
#自动生成depart_id列
depart=models.ForeignKey(to="Department",to_field="id")
#级联删除
depart=models.ForeignKey(to="Department",to_field="id",on_delete=models.CASCADE)
#置空
depart=models.ForeignKey(to="Department",null=True,blank=True,to_field="id",on_delete=models.SET_NULL)
```
#### 2.9.5.3 性别
```
GENDER_CHOICES=(
(1,"男"),
(2,"女"),
)
gender=models.SmallInterger(verbose_name="sex",choices=GENDDER_CHOICES)
```
```python
for obj in queryset:
obj.get_gender_display()#模板里不加括号
obj.depart.title;#直接获取关联表的对象
```
#### 2.9.5.4 python 时间 datatime 转字符
```
obj.create_time.strftime("%Y-%m-%d")
模板里:{{item.event_start|date:"Y-m-d H:i:s"}}
```
### 2.10 新建用户 Form and ModelForm
1.原始
2.django 组件:form 组件,modelform 组件
```
from django import forms
```
#### 2.10.1 Form
```python
class myform(Form):
user=forms.CharField(widget=forms.Input)#input框插件
pwd=forms.CharField(widget=forms.Input)
email=forms.CharField(widget=forms.Input)
def user_add(request):
if...:
form=myform()
return render(xx,xx,{'form':form})
tempaltes:
{{form.user}}
{{form.pwd}}
...
or: {%for field in form%}
{{field}}
{{field.errors}}
{%endfor%}
```
#### 2.10.2 ModelForm
```
from django import forms
```
```python
class myform(forms.ModelForm):
class Meta:
model=models.UserInfo
fields=["name","password","age"]
def xxx(rq):
form = myform()
return xxx
```
生成 input 框:
```python
{{form.name}}
```
```
#取备注
{{form.name.label}}:{{form.name}}
{%for field in form%}
{{field.label}}:{{field}}
{%endfor%}
```
对象返回要求的值:
```python
class myform(forms.ModelForm):
class Meta:
model=models.UserInfo
fields=["name","password","age"]
def __str__(self):
return self.title
```
样式:
```python
widgets={
"name":forms.TextInput(attrs={"class":"form-control"})
}
#
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
for name.foeld in self.fields.items():#name字段名字
field.widget.attrs={"class":"form-control","placeholder":field.label}
```
校验数据:
```python
form=UserModelForm(data=request.POST)
if form.is_valid():
form.save()#保存到数据库
else:
# print(form.errors)
return render()
```
zh-hans
替代 placeholder:
```python
row_object = models....first()
form = UserModeForm(instance=row_object)
```
不新增同一对象:
```
form=userModelform(data=re.POST,instance=row_object)
```
新增其他值:
```
form.instance.字段名 = xxx
```
### 2.11 html 继承
```
{%extends 'layout.html'%}
{%block content自定义名字%}
{%endblock%}
```
# 五.web 通识
```js
```
标签:__,name,models,FullStack,####,var,### From: https://www.cnblogs.com/alexmaodali/p/18112516