• 事务 和 锁


    事务和锁

     1 select * from t1 where id=1 for update;
     2 models.T1.objects.select_for_update().fitler(id=1)
     3 
     4 事务
     5 1 全局的,就是settings配置文件配置
     6 2 局部
     7     视图函数
     8     from django.db import transaction
     9     @transaction.atomic
    10     def index(request):
    11         pass orm...sql..
    12         return xxx
    13     上下文逻辑里面加
    14     def index(request):
    15         ..
    16         with transaction.atomic():
    17             pass orm...sql..
    18         ...
    19         return xxx

    ajax

     1 特性:
     2     1. 异步请求
     3     2. 局部刷新
     4     # ret = requests.post('/login/',data={})  print(ret.content)
     5     
     6     $.ajax({
     7         url:'/login/', #请求路径
     8          type:'post' ,   #请求方式
     9         data:{
    10             username:$('#username').val(),
    11             password:$('#password').val(),
    12             csrfmiddlewaretoken:
    13             },
    14             
    15         success:function(response){
    16             response  #响应内容
    17             var resStr = JOSN.parse(respone);
    18             # {"aa":0,"bb":"/index/"}
    19             if (resStr['aa'] === 0){
    20                 // alert('xx')
    21                 locaction.href=resStr['bb'];
    22                 location.href='/index/';
    23             }
    24             else{
    25                 ...
    26             
    27             }
    28             
    29         
    30         }
    31     })
    32 
    33 view.py  看代码

    外部文件导入的方式来写js代码,那么js代码中不能写django的模板语法,因为html文件的加载顺序:url--视图--html模板渲染 --- return给浏览器 -- 浏览器渲染 --- srcipt的src --才去请求js文件 --那么这个js文件的代码此时才加载到你的html文件中 -- 就没有模板渲染的步骤了 -- 就没有办法替换对应的模板语法.



    Q查询

    1 Q()   &  |  ~
    2 models.Book.objects.filter(Q(good__gt=100)|Q(comment__gt=100))
    3 models.Book.objects.filter(Q(good__gt=100)|Q(comment__gt=100)&Q(price__gt=100))
    4 models.Book.objects.filter(Q(Q(good__gt=100)|Q(comment__gt=100))&Q(price__gt=100))
    5 models.Book.objects.filter(~Q(good__gt=100)|Q(comment__gt=100),price__gt=100) 

    sql_mode

    1 only_full_group_by
    2 select * from book;
    3 select publish_id,Avg(price) from book group by publish_id; 
    4 没有 only_full_group_by
    5 select *,avg(price) from book group by publish_id; 
    6 select *,max(price) from book group by publish_id;

    F查询

    1 models.Book.objects.filter(good__gt=F('comment'))
    2 models.Book.objects.all().update(price=F('price')+20)
  • 相关阅读:
    攀岩
    插入排序
    runtime error
    vector
    旅行家
    九键字母组合
    [蓝桥杯][基础训练]Sine之舞
    代码计算程序运行的时间
    max_element
    distance
  • 原文地址:https://www.cnblogs.com/ch2020/p/13203023.html
Copyright © 2020-2023  润新知