Python Django-AttributeError:module';操作系统&x27;没有属性';环境';
在学习Django的上下文中,我需要使用Faker模块用随机数据填充Sqlite 在models.py下创建了多个模型:Python Django-AttributeError:module';操作系统&x27;没有属性';环境';,python,django,macos,visual-studio-code,pylint,Python,Django,Macos,Visual Studio Code,Pylint,在学习Django的上下文中,我需要使用Faker模块用随机数据填充Sqlite 在models.py下创建了多个模型: from django.db import models class Topic(models.Model): top_name = models.CharField(max_length=264,unique=True) def __str__(self): return self.top_name class Webpage(mode
from django.db import models
class Topic(models.Model):
top_name = models.CharField(max_length=264,unique=True)
def __str__(self):
return self.top_name
class Webpage(models.Model):
topic = models.ForeignKey(Topic,on_delete=models.DO_NOTHING)
name = models.CharField(max_length=264,unique=True)
url = models.URLField(unique=True)
def __str__(self):
return self.name
class AccessRecord(models.Model):
name = models.ForeignKey(Webpage,on_delete=models.DO_NOTHING)
date = models.DateField()
def __str__(self):
return str(self.date)
为了随机填充这些模型,我使用以下脚本(populate\u first\u app.py):
当我运行populate_first_app.py时,出现以下错误:
AttributeError:模块“os”没有属性“environment”
使用VisualStudio代码(v1.39.2),我陷入了困境
视觉代码在以下行中突出显示错误:
t = Topic.objects.get_or_create(top_name=random.choice(topics))[0]
类“Topic”没有“objects”memberpylint(没有成员)
我使用以下命令安装了pylint:
pip3 install pylint-django
但还是卡住了。电话应该是
os.environ.setdefault('DJANGO\u SETTINGS\u MODULE','first\u project.SETTINGS')
有关更多详细信息,请参见前面的问题,如以下问题:
尝试
os.environment
而不是os.environment
pip3 install pylint-django