模塊七:web開發進階筆記
阿新 • • 發佈:2018-05-25
多行匹配1、JS 正則
test - 判斷字符串是否符合規定的正則 rep = /\d+/; rep.test("asdfoiklfasdf89asdfasdf") # true rep = /^\d+$/; rep.test("asdfoiklfasdf89asdfasdf") # true exec - 獲取匹配的數據 rep = /\d+/; str = "wangshen_67_houyafa_20" rep.exec(str) # ["67"] JavaScript is more fun than Java or JavaBeans! var pattern = /\bJava(\w*)\b/; # ["JavaScript", "Script"] JavaScript is more fun than Java or JavaBeans! var pattern = /\bJava\w*\b/g; # ["JavaScript"] # ["Java"] # ["JavaBeans"] # null JavaScript is more fun than Java or JavaBeans! var pattern = /\bJava(\w*)\b/g; # ["JavaScript",‘Script‘] # ["Java", ""] # ["JavaBeans", "Beans"] # null 多行匹配: 默認就是多行匹配 ^$
-
登錄註冊驗證
默認事件先執行:
checkbox
自定義先執行
a
submit
...
<form><input type=‘type‘ /> <input type=‘password‘ /> <input type=‘submit‘ /> </form> $(‘:submit‘).click(function(){ $(‘:text,:password‘).each(function(){ ... return false; }) return false; }) input,checbox
================================== 驗證 ================================
JS: 驗證各種驗證 $(‘:submit‘).click(function(){ $(‘:text,:password‘).each(function(){ ... return false; }) return false; })
後端:python實現
業務處理
....
2、組件
BootStrap - css - js 學習 BootStrap 規則 一、響應式 @media 二、圖標、字體 @font-face 三、基本使用 ========》 後臺管理 jQueryUI * - css - js 學習 jQueryUI 規則 EasyUI - css - js 學習 jQueryUI 規則 ============ Ajax操作 ================
3、WEB框架
MVC
Model View Controller
數據庫 模板文件 業務處理
MTV
Model Template View
數據庫 模板文件 業務處理
############## WEB:MVC、MTV
4、Django
pip3 install django
C:\Python35\Scripts
# 創建Django工程
django-admin startproject 【工程名稱】
mysite
- mysite # 對整個程序進行配置
- init
- settings # 配置文件
- url # URL對應關系
- wsgi # 遵循WSIG規範,uwsgi + nginx
- manage.py # 管理Django程序:
- python manage.py
- python manage.py startapp xx
- python manage.py makemigrations
- python manage.py migrate
# 運行Django功能
python manage.py runserver 127.0.0.1:8001
chouti
- chouti
- 配置
- 主站 app
- 後臺管理 app
# 創建app
python manage.py startapp cmdb
python manage.py startapp openstack
python manage.py startapp xxoo....
app:
migrations 數據修改表結構
admin Django為我們提供的後臺管理
apps 配置當前app
models ORM,寫指定的類 通過命令可以創建數據庫結構
tests 單元測試
views 業務代碼
1、配置模板的路徑
TEMPLATES = [
{
‘BACKEND‘: ‘django.template.backends.django.DjangoTemplates‘,
‘DIRS‘: [os.path.join(BASE_DIR, ‘templates‘)],
‘APP_DIRS‘: True,
‘OPTIONS‘: {
‘context_processors‘: [
‘django.template.context_processors.debug‘,
‘django.template.context_processors.request‘,
‘django.contrib.auth.context_processors.auth‘,
‘django.contrib.messages.context_processors.messages‘,
],
},
},
]
2、配置靜態目錄
static
STATICFILES_DIRS = (
os.path.join(BASE_DIR, ‘static‘),
)
<link rel="stylesheet" href="/static/commons.css" />
內容整理
-
創建Django工程
django-admin startproject 工程名 -
創建APP
cd 工程名
python manage.py startapp cmdb3、靜態文件
project.settings.pySTATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), )
4、模板路徑
DIRS ==> [os.path.join(BASE_DIR,‘templates‘),]
5、settings中
middlerware # 註釋 csrf
6、定義路由規則
url.py"login" --> 函數名
7、定義視圖函數
app下views.pydef func(request): # request.method GET / POST # http://127.0.0.1:8009/home?nid=123&name=alex # request.GET.get(‘‘,None) # 獲取請求發來的而數據 # request.POST.get(‘‘,None) # return HttpResponse("字符串") # return render(request, "HTML模板的路徑") # return redirect(‘/只能填URL‘)
8、模板渲染
特殊的模板語言-- {{ 變量名 }} def func(request): return render(request, "index.html", {‘current_user‘: "alex"}) index.html <html> .. <body> <div>{{current_user}}</div> </body> </html> ====> 最後生成的字符串 <html> .. <body> <div>alex</div> </body> </html> -- For循環 def func(request): return render(request, "index.html", {‘current_user‘: "alex", ‘user_list‘: [‘alex‘,‘eric‘]}) index.html <html> .. <body> <div>{{current_user}}</div> <ul> {% for row in user_list %} {% if row == "alex" %} <li>{{ row }}</li> {% endif %} {% endfor %} </ul> </body> </html> #####索引################# def func(request): return render(request, "index.html", { ‘current_user‘: "alex", ‘user_list‘: [‘alex‘,‘eric‘], ‘user_dict‘: {‘k1‘: ‘v1‘, ‘k2‘: ‘v2‘}}) index.html <html> .. <body> <div>{{current_user}}</div> <a> {{ user_list.1 }} </a> <a> {{ user_dict.k1 }} </a> <a> {{ user_dict.k2 }} </a> </body> </html> ###### 條件 def func(request): return render(request, "index.html", { ‘current_user‘: "alex", "age": 18, ‘user_list‘: [‘alex‘,‘eric‘], ‘user_dict‘: {‘k1‘: ‘v1‘, ‘k2‘: ‘v2‘}}) index.html <html> .. <body> <div>{{current_user}}</div> <a> {{ user_list.1 }} </a> <a> {{ user_dict.k1 }} </a> <a> {{ user_dict.k2 }} </a> {% if age %} <a>有年齡</a> {% if age > 16 %} <a>老男人</a> {% else %} <a>小鮮肉</a> {% endif %} {% else %} <a>無年齡</a> {% endif %} </body> </html>
XXOO管理:
MySQL
SQLAlchemy
主機管理(8列):
IP
端口
業務線
...
用戶表:
用戶名
密碼
功能:
1、 登錄
2、主機管理頁面
- 查看所有的主機信息(4列)
- 增加主機信息(8列) ** 模態對話框
3、查看詳細
url:
"detail" -> detail
def detail(reqeust):
nid = request.GET.get("nid")
v = select * from tb where id = nid
...
4、刪除
del_host -> delete_host
def delete_host(request):
nid = request.POST.get(‘nid‘)
delete from tb where id = nid
return redirect(‘/home‘)
模塊七:web開發進階筆記