问题描述
创建个人档案模型时出现以下错误
I got the following error when I created Profile model
这是我创建的代码的片段
This is the snippet of the code I created
from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
image = models.ImageField(default="default.jpg", upload_to="profile_pics")
def __str__(self):
return f"{self.user.username} Profile"
以前运行正常。现在,突然我收到了这个错误。我不明白该错误的含义。我该如何解决?
谢谢
previously it was working fine. Now, all of a sudden I am getting this error.I didn't understand the meaning of this error. How do I solve it?Thank you
推荐答案
为了使pylint与Django正常工作,您应该安装 pylint-django
packege:
In order for pylint to work properly with Django you should install the pylint-django
packege:
pip install pylint-django
然后您可以使用 pylint_django $ c运行
pylint
$ c>作为插件:
Then you can run pylint
with pylint_django
as a plugin:
pylint --load-plugins pylint_django <path_to_django_file>
如果您将VSCode用作IDE,则可以将此代码段添加到 .vscode / settings.json
文件为您的项目加载插件:
If you are using VSCode as your IDE, you can add this snippet to your .vscode/settings.json
file to load the plugin for your project:
{
"python.linting.pylintArgs": [
"--load-plugins",
"pylint_django"
]
}
或者,如果您有 .pylintrc
文件,则可以添加此行以加载插件:
Or, if you have a .pylintrc
file, you can add this line to load the plugin:
[MASTER]
load-plugins=pylint_django
这篇关于“ OneToOneField”的实例没有“用户名”成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!