我想将标题限制在3到25个字符之间。我无法让MinLengthValidator工作。我是Pycharm和python的新手
class Video(models.Model):
title = models.CharField(max_length=255)
url = models.URLField()
youtube_id = models.CharField(max_length=255)
def clean_title_length(self):
data = self.cleaned_data['title']
length= len(data)
if length < 3 or length > 25:
raise ValidationError("The length of the title must be
between 3 and 25 characters")
else:
return data
def add_video(request):
form = VideoForm()
if request.method == 'POST':
filled_form = VideoForm(request.POST)
if filled_form.is_valid():
以上表格始终返回有效。
有关如何使此范围验证器工作的建议?
TIA
数据是“标题”,因此您的长度始终为5