Django属性错误:'function'对象没有属性' self '
这是我的model.py文件,我收到以下错误:
from django.db import models
# Create your models here.
import uuid
from rgbfield.fields import RGBColorField
class Category(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
index = models.IntegerField(unique=True, db_index=True)
name = models.CharField(unique=True, max_length=100)
abbreviation = models.CharField(max_length=4, unique=True)
theme_color = RGBColorField(default="#fff")
text_color = RGBColorField(default="#000")
def __str__(self):
return self.name
class Tool(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(unique=True, db_index=True, max_length=100, help_text="The name of your tool (must be unique)")
byline = models.CharField(max_length=100,help_text="The byline of your tool (can contain HTML)")
description = models.TextField(help_text="A description of your tool (can contain HTML)")
logo_image = models.ImageField(upload_to='image', blank=True, help_text="Use to upload an (optional) logo image for your tool")
logo_link = models.URLField(blank=True, help_text="An (optional) link to be associated with your tool's logo")
about_link = models.URLField(blank=True, help_text="An (optional) link to further information about your tool")
install_link = models.URLField(blank=True, help_text="An (optional) link to local installation information for your tool")
launch_link = models.URLField(blank=True, help_text="An (optional) link to launch your tool. If hosted by EMAC, leave this blank.")
categories = models.ManyToManyField(Category, related_name="tools")
is_external = models.BooleanField(default=True)
def tool_directory_path(instance, filename):
# Image file will be uploaded to MEDIA_ROOT/tools/<id>/<filename>
return "tools/{0}/{1}".format(instance.id, filename)
def __str__(self):
return self.name
我已检查过所有内容,但不知道导致此错误的原因。任何导致错误的见解都会非常有用。
这是view.py文件
from django.shortcuts import render
from django.http import HttpResponse
from .models import Category, Tool
# Create your views here.
def homepage(request):
category = Category.objects.all()
tool = Tool.objects.all()
context = {
'Tool': tool,
'Category': category,
}
return render(request, 'index.html',context)