Edit: Still have this issue.
Visual Studio Code throws the following error:
User model imported from django.contrib.models
The error appears in line 2 of the following script (models.py).
The code is from a Django tutorial and works fine. But it is annoying that Visual Studio Code (Pylint) throws an error (and marks the script red).
from django.db import models
from django.contrib.auth.models import User
from django.utils import timezone
# Create your models here.
class Post(models.Model):
title = models.CharField(max_length=100)
content = models.TextField()
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return self.title
Also VSC throws an error when importing a custom model, e.g. Post.
from app_blog.models import Post.
The error: Unable to import 'app_blog.models'
My setup:
- Win10
- Virtual Enviroment (Python, Django, Pylint, ...)
- Django 3.1.1
- Python 3.8.5
- Pylint Django
- VSC runs Python in my VENV
Pylint settings:
"python.linting.pylintArgs": [
"--load-plugins=pylint_django",
"--errors-only"
],
"python.linting.pylintUseMinimalCheckers": true
There are the following interpreter, Interpreter No. 2 is selected.
- Python 3.8.3 64-bit ('base': conda),
~\Anaconda3\python.exe - Python 3.8.5 64-bit('venv'),
.\venv\Scripts\python.exe - Python 3.8.5 64-bit,
~\AppData\Local\Programs\Python\Python38\python.exe