我正在阅读Django 2 By Example一书,在书中我试图构建一个具有标记功能的博客应用程序。
我包含django-taggit
的代码(在使用pip安装0.22.2版本之后(如下。
将应用程序添加到INSTALLED_APPS
:
INSTALLED_APPS = [
#...
'blog.apps.BlogConfig',
'taggit',
]
将django-taggit
提供的TaggableManager
添加到Post
模型中。
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
from django.urls import reverse
from taggit.managers import TaggableManager
# Create your models here.
class PublishedManager(models.Manager):
def get_queryset(self):
return super(PublishedManager, self).get_queryset().filter(status='published')
class Post(models.Model):
STATUS_CHOICES = (
('draft', 'Draft'),
('published', 'Published'),
)
title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250, unique_for_date='publish')
author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='blog_posts')
body = models.TextField(default='')
publish = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='draft')
objects = models.Manager() # The default manager.
published = PublishedManager() # Our custom manager.
tags = TaggableManager()
def get_absolute_url(self):
return reverse('blog:post_detail',
args=[self.publish.year,
self.publish.month,
self.publish.day,
self.slug])
class Meta:
ordering = ('publish',)
def __str__(self):
return self.title
当我将行tags = TaggableManager()
添加到Post
模型中时,当我试图通过管理站点添加新帖子或编辑现有帖子时,会出现以下错误:
TypeError: render() got an unexpected keyword argument 'renderer'
。
我不知道为什么会产生这个错误,所以任何建议都将不胜感激。
我遇到了同样的问题,我解决了安装django-taggit 0.23.0
的问题
我输入virtualenv:pip install django-taggit==0.23.0
我希望这对你有所帮助。致以最良好的问候。
我在这个链接上找到了答案。https://github.com/froala/django-froala-editor/issues/55
解决方案:导航到django/forms/boundfields.py并删除第93行(renderer=self.form.renderer(。