摘要:如何在Django当中使用数据库锁呢?局部事务锁。通过上下文管理。 # 事务 with transaction.atomic(): # 在数据库中加锁 select * from customer where id in [11,22] for update origin_queryset = mo
阅读全文
摘要:在models.Model中会遇到 limit_choices_to ,这个是什么意思呢? 在使用ModelForm渲染前端页面的时候,当model字段为ForeignKey的时候,会被渲染成select单选框, model字段为ManyToMany的时候会被渲染成多选select款。 当你在mod
阅读全文
摘要:在python当中自己写一个分页器,而不是直接运用Django中的分页器组件。 1.py 1 """ 2 分页组件 3 """ 4 5 6 class Pagination(object): 7 def __init__(self, current_page, all_count, base_url
阅读全文
摘要:# models.pyfrom django.db import models # Create your models here. class UserInfo(models.Model): name = models.CharField(max_length=32,verbose_name='用
阅读全文
摘要:在Django当中需要进行文件的上传,那么有哪几种方式呢?自己总结了下,有如下几种方法。 方式一:基于form表单进行上传。 index.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>xx</t
阅读全文
摘要:Django当中的inclusion_tag,来源于 from django.template import Library 属于Library下的一个方法。 主要作用:通过渲染一个模板来显示一些数据。属于自定义标签的一种。 项目实现:为了能够在页面中一栏上显示一级菜单 1.templatetags
阅读全文
摘要:url : http://127.0.0.1:8001/rbac/role/edit/?page=2 1.request.path: request.path仅提供相对于根目录的url相对路径,不包含参数。它的输出是一个字符串,结果如下所示:/rbac/role/edit/ 2.request.pa
阅读全文
摘要:import refrom collections import OrderedDictfrom django.conf import settingsfrom django.utils.module_loading import import_stringfrom django.urls.reso
阅读全文