save值的修改
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">updateView</span><span class="hljs-params">(req)</span>:</span>
u = User.objects.get(pk=<span class="hljs-number">11</span>)
u.username = <span class="hljs-string">'zhangsan'</span>
u.save()
<span class="hljs-keyword">return</span> HttpResponse(<span class="hljs-string">'save修改'</span>)
update的值的修改
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">updateView</span><span class="hljs-params">(req)</span>:</span>
u = User.objects.filter(id__in = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>])
u.update(sex=<span class="hljs-keyword">True</span>)
<span class="hljs-keyword">return</span> HttpResponse(<span class="hljs-string">'update修改多个值'</span>)
区别
delete()
<span class="hljs-comment">#删除数据</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">delete</span><span class="hljs-params">(req)</span>:</span>
u = User.objects.get(pk=<span class="hljs-number">1</span>)
u.delete()
<span class="hljs-keyword">return</span> HttpResponse(<span class="hljs-string">'删除数据'</span>)