类型对象 'Skills' 没有属性 'objects'

type object 'Skills' has no attribute 'objects'

我收到此错误“类型对象 'Skills' 没有属性 '_default_manager'”

我在尝试 运行 我的 Django 项目

时收到以下错误“类型对象 'Skills' 没有属性 'objects'”

views.py

from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from django.utils import timezone
from portfolio_app.models import GuestUser,InquiryForm,Skills,Facts,Education,Service,UserTestimonials
from .forms import GuestUser,InquiryForm,Skills,Facts,Education,Service,UserTestimonials
from django.views.generic import (TemplateView,ListView,
                                          DetailView,CreateView,
                                          UpdateView,DeleteView)
from django.views import generic
from django.urls import reverse_lazy
from django.contrib.auth.mixins import LoginRequiredMixin



class TestView(generic.ListView):
     model = Skills
     template_name = 'portfolio_app/test.html'

models.py

from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse

class Skills(models.Model):
    skill_name = models.CharField(max_length=100)
    skill_value = models.CharField(max_length=50)
    def __str__(self):
        return self.skill_name

test.html

{% extends 'portfolio_app/base.html' %}
{% load static %}
{% block content %}


{% for skill in skills_list %}  
{{skill.skill_name}}}
{% endfor %}
{% endblock %}

urls.py

from django.urls import path
from portfolio_app.models import *
from . import views

urlpatterns = [
    path('',views.fact,name='index'),
    #path('index/',views.SkillView.as_view,name='index'),
    path('about/',views.about_me,name='about'),
            
    path('service/',views.ServiceView.as_view(),name='service'),
            path('resume/',views.ResumeView.as_view(),name='resume'),
            
    path('contact/',views.ContactView.as_view(),name='contact'),
    path('test/',views.TestView.as_view(),name='test'),
]

请帮忙 我在尝试 运行 我的 Django 项目

时收到以下错误“类型对象 'Skills' 没有属性 'objects'”

你有不明确的导入:

from portfolio_app.models Skills
from .forms Skills

您可以像这样更改模型导入:

from portfolio_app.models Skills as SkillsModel

然后使用 SkillsModel 而不是 Skills:

class TestView(generic.ListView):
       model = SkillsModel
       template_name = 'portfolio_app/test.html'

或者您可以删除不必要的 .forms 导入。