我有一个PythonDjango应用程序,在Pylance自动安装之前一直运行良好。现在我得到一个错误:发生异常:
我的代码是:我有一个PythonDjango应用程序,在Pylance自动安装之前一直运行良好。现在我得到一个错误:发生异常:,python,django,Python,Django,我的代码是: from django.shortcuts import render # Create your views here. from django.views.generic import ListView # <- new from .models import Post def home(request): context = { 'posts': Post.objects.all() } return ren
from django.shortcuts import render # Create your views here.
from django.views.generic import ListView # <- new
from .models import Post
def home(request):
context = {
'posts': Post.objects.all()
}
return render(request, 'blog/home.html', context)
任何帮助都将不胜感激。请共享异常的完整回溯。没有回溯。当我打开项目时,错误是Post下面的旋转线,表示它在view.py中找不到Post。它位于models.py文件中。错误是类“Post”没有“objects”memberpylint(没有成员)。
Post is defined in:
from django.db import models # Create your model fields here.
from django.utils import timezone # for the DateTimeZone field below
from django.contrib.auth.models import User # the author field below needs this
class Post(models.Model):
title = models.CharField(max_length=100)
content = models.TextField() # TextField has no length limitation
date_posted = models.DateTimeField(default=timezone.now) # Use the django timezone
author = models.ForeignKey(User, on_delete=models.CASCADE) # if the User is deleted, so will this model
def __str__(self):
return self.title