嗨,我正在尝试将ckeditor集成到我的博客中,这是错误正在寻求帮助 当我尝试使用ckeditor_uploader.fields导入RichTextUploadingField,RichTextField, 错误无法导入RichTextField models.py
from django.db import models
from django.template.defaultfilters import slugify
from django.conf import settings
from taggit.managers import TaggableManager
from ckeditor_uploader.fields import RichTextUploadingField
class Post(models.Model):
STATUS_CHOICES=(
('Published','Published'),
('Draft','Draft'),
)
user = models.ForeignKey(settings.AUTH_USER_MODEL,default=1,on_delete=models.CASCADE)
title = models.CharField(max_length=250)
body = models.RichTextUploadingField()
Category=models.ForeignKey(Category,on_delete=models.CASCADE)
seo_title = models.CharField(max_length=60,blank=True,null=True)
seo_description = models.CharField(max_length=125,blank=True,null=True)
slug = models.SlugField(max_length=200,unique=True)
status = models.CharField(max_length=10,default='Draft',choices=STATUS_CHOICES)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
thumb=models.ImageField(blank=True)
tags = TaggableManager()
def save(self,*args,**kwargs):
self.slug=slugify(self.title)
super(Post,self).save(*args,**kwargs)
def __str__(self):
return self.title
def snippet(self):
return self.body[:300]+'....'
#def get_absolute_url(self):
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pages',
'blog',
'django_social_share',
'taggit',
'ckeditor',
'ckeditor_uploader',
]
STATIC_URL = '/static/'
STATICFILES_DIRS=[
os.path.join(BASE_DIR,'static'),
]
MEDIA_URL='/media/'
MEDIA_ROOT=os.path.join(BASE_DIR,'media')
#PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
#STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'static')
#...
SITE_ID = 1
####################################
## CKEDITOR CONFIGURATION ##
####################################
CKEDITOR_JQUERY_URL = 'https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js'
CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_IMAGE_BACKEND = "pillow"
CKEDITOR_CONFIGS = {
'default': {
'toolbar': None,
},
}
还尝试使用从ckeditor.fields导入的导入RichTextField说无法从RichTextField导入
答案 0 :(得分:0)
您正在使用:models.RichTextUploadingField()
实际上不是模型模块类,是从另一个库中导入的,因此您应该仅使用body = RichTextUploadingField()
。