Locks: shared locks and exclusive locks
- lock in share mode shared lock to open the way (they have to open things, begin)
- for update exclusive lock open (to begin)
- Table lock Example: lock table app01_publish write
- unlock tables;
- create, update, delete, operation, MySQL automatic row-level mutex
`
Lock
1. protostele
select * from t1 where id = 1 for update; ( before writing the sentence have to open things, the begin)
2.orm in
. Models.T1.objects.select_for_update () filter (id = 1 )Four characteristics of things: atomicity, permanent, isolation, consistency.
原生SQL中开启事物的两种方式: 1.start transaction; 2.beigin; 提交事物 commit; 回滚 roll_back orm中开启事物的三种方式 1. DATABASES = { 'ENGINE':'django.db.backends.mysql', 'NAME':'day58', 'HOST':'127.0.0.1', 'PORT':3306, 'USER':'root', 'PASSWORd':'root', 'ATOMIC_REQUESTS':TRUE, # 全局开启事物,绑定的是http请求响应整个过程 } 2. from django.db import transaction @transaction.atomic def viewfunc(request): do_stuff() 取消事物 @transaction.non_atomic_requests def my_view(request): do_stuff() 3.上下文 from django.db import transaction def viewfunc(request): do_stuff() with transaction.atomic(): do_more_stuff() do_other_stuff()
Ajax (jQuery in): two features
- Asynchronous request
- Partial refresh
$('#button').click(function(){ $.ajax({ url:'/login/', # 请求路径 type:'post', # 请求方式 data:{ # 请求携带数据 uname:$('#username'.val()), pwd:$('#password'.val()), csrfmiddlewaretoken:$('[name=csrfmiddlewaretoken]') #csrfmiddlewaretoken:"{{csrf_token}}" }, success:function(res){ console.log(res) }, error:function(jqXHR,textStatus,err){ console.log(arguments) } }) }) 爬虫中的请求: ret = requests.post('/login/',data={}) print(ret.content)
Way external js file import to write code, then JS Code Summary Django template syntax can not be used, because the load order of the HTML file: URL- view ---- HTML template rendering --return to the browser - browser rendering - script of SRC- before going to request js file ---- JS file so the code at this time only to load into your HTML inside.
ajax use
Guess you like
Origin www.cnblogs.com/he-qing-qing/p/11264800.html
Recommended
Ranking