Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 名称错误:名称';RegexValidator';没有定义_Python_Django_Python 2.7_Django Models - Fatal编程技术网

Python 名称错误:名称';RegexValidator';没有定义

Python 名称错误:名称';RegexValidator';没有定义,python,django,python-2.7,django-models,Python,Django,Python 2.7,Django Models,这是my models.py中的代码 from django.db import models class Person(models.Model): contactNumber = models.IntegerField(max_length = 11, unique = True, validators = [[RegexValidator(regex='^\d{11}$', message='Length has to be 11 numbers including 0', c

这是my models.py中的代码

from django.db import models

class Person(models.Model):
     contactNumber = models.IntegerField(max_length = 11, unique = True, validators = [[RegexValidator(regex='^\d{11}$', message='Length has to be 11 numbers including 0', code='Invalid number')]])
     picture = models.ImageField(upload_to = 'folder_name', default = 'folder_name/default-image.jpg')
     jobTitle = models.CharField(max_length = 30)
运行
python manage.py sql individual
时,contactNumber字段出现此错误

name错误:未定义名称“RegexValidator”

这是图片字段的错误

django.core.exceptions.impropertlyconfigured:枕头和PIL都无法导入:没有名为Image的模块


我不熟悉Python和Django。我应该怎么做才能更正这两个字段?

这是基本的Python,为了使用任何需要在当前模型中定义或导入的内容。在您的情况下,需要从django.core.validators导入模型文件顶部的RegexValidator


对于第二个问题,错误消息告诉您需要知道的一切:您需要在系统中安装Pillow或(不太理想的)PIL。的文档中提到了这一点,并提供了相关链接。

您可能需要导入它

 from django.core.validators import RegexValidator
此外,您需要安装枕头,然后才能使用它