gpt4 book ai didi

NameError: name 'Task' is not defined(NameError:未定义名称‘Task’)

转载 作者:bug小助手 更新时间:2023-10-25 19:01:44 27 4
gpt4 key购买 nike



please someone help me to solve this problem

请谁来帮我解决这个问题


# **Admin.py**
from django.contrib import admin
from .models import Task

admin.site.register(Task)

# **view.py**
from django.shortcuts import render
from django.views.generic.list import ListView
from .models import Task

class TaskList(ListView):
model = Task
context_object_name = 'tasks'
{Error
from .models import Task
ImportError: attempted relative import with no known parent package}


# **Model.py**
from django.db import models
from django.contrib.auth.models import User



# Create your models here.
class Task(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True)
title = models.CharField(max_length=200)
description = models.TextField(null=True,blank=True)
complete = models.BooleanField(default=False)
create = models.DateTimeField(auto_now_add=True)

def __str__(self):
return self.title

class Meta:
ordering = ['complete']

**
when is run on server the specific result on come and but server works perfectly.
when i run the code its send this error

**当在服务器上运行时,特定的结果会出现,但服务器运行得很好。当我运行代码时,它发送这个错误


更多回答
优秀答案推荐
更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com