Then in Visual Studio Code goto: User Settings (Ctrl + , or File > Preferences > Settings if available ) Put in the following (please note the curly braces which are required for custom user settings in VSC):
@tieuminh2510 answer is perfect. But in newer versions of VSC you will not find thhe option to edit or paste that command in User Settings.
Now in newer version to add that code follow this steps :
Press ctr+sft+P to open the the Command Palette. Now in command palette type Preferences: Configure Language Specific Settings.
Now select Python. Here in right side paste this code
That’s not an error, it’s just a warning from VSC. Django adds that
property dynamically to all model classes (it uses a lot of magic
under the hood), so the IDE doesn’t know about it by looking at the
class declaration, so it warns you about a possible error (it’s not).
objects is in fact a Manager instance that helps with querying the DB.
If you really want to get rid of that warning you could go to all your
models and add objects = models.Manager() Now, VSC will see the
objects declared and will not complain about it again.
I’ve tried all possible solutions offered but unluckly my vscode settings won’t changed its linter path. So, I tride to explore vscode settings in settings > User Settings > python. Find Linting: Pylint Path and change it to “pylint_django”. Don’t forget to change the linter to “pylint_django” at settings > User Settings > python configuration from “pyLint” to “pylint_django”.
But after that, you will notice a lot of new linting errors. Then, read what it said here:
These arguments are passed whenever the python.linting.pylintUseMinimalCheckers is set to true (the default). If you specify a value in pylintArgs or use a Pylint configuration file (see the next section), then pylintUseMinimalCheckers is implicitly set to false.
What I have done is creating a .pylintrc file as described in the link, and then, configured the following parameters inside the file (leaving the rest of the file untouched):
By doing Question = new Question() (I assume the new is a typo) you are overwriting the Question model with an intance of Question. Like Sayse said in the comments: don’t use the same name for your variable as the name of the model. So change it to something like my_question = Question().
Change your linter to – flake8 and problem will go away.
回答 13
当我使用pylint_runner时发生此问题
所以我要做的是打开.pylintrc文件并将其添加
# List of members which are set dynamically and missed by pylint inference# system, and so shouldn't trigger E1101 when accessed. Python regular# expressions are accepted.
generated-members=objects
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
# expressions are accepted.
generated-members=objects