RegexValidator校验器: 在自定义的form组件类设置字段validators的值,引入RegexValidator模块 from django import forms from django.core.validators import RegexValidator from django.core.exceptions import ValidationError class Myform(forms.Form): name = forms.CharField( # requi
1.从is_valid方法入手 def is_valid(self): """Return True if the form has no errors, or False otherwise.""" return self.is_bound and not self.errors 如果is_valid要返回True的话,那么self.is_bound要为True并且self.errors要为Flase(字面意思上看errors为False的话,
批量插入数据 bulk_create # 1.往书籍表中插入数据 1000 # for i in range(1000): # 这种插入方式 效率极低 # models.Book.objects.create(title='第%s本书'%i) book_list = [] for i in range(100000): # 时间还是很短 两者差距很大 book_list.append(models.Book(title='第%s本书'%i)) models.Book.objects.bulk_c