CKEditor хорошо работает с RichTextField, но CKEditor Uploader не работает с RichTextUploadingField в Django
Я изучаю Django Framework и пытаюсь интегрировать CKEditor в свой проект. Вот мои модели:
from django.db import models
# Create your models here.
import datetime
from ckeditor.fields import RichTextField
from ckeditor_uploader.fields import RichTextUploadingField
# Create your models here.
class Category (models.Model):
name = models.CharField(max_length=150, unique=True)
intro= RichTextUploadingField(blank=True)
def __str__(self):
return self.name
class Story(models.Model):
category = models.ForeignKey (Category, on_delete=models.PROTECT)
name = models.CharField(max_length=250, unique=True)
author = models.CharField(max_length=250)
url = models.URLField(null=True)
content = RichTextField(blank=True)
public_day= models.DateField(default=datetime.date.today)
image= models.ImageField(upload_to="stories/images", default="stories/images/default.jpg")
def __str__(self):
return self.name
RichTextField применяется и работает хорошо, но я не знаю, почему я не могу интегрировать RichTextUploadingField из CKEditorUploader в мое поле Category at intro (как показано на рисунке 2)
вот моя настройка:
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')
STATIC_ROOT=os.path.join(BASE_DIR,'static/')
#ckeditor setting
CKEDITOR_BASEPATH = '/static/ckeditor/ckeditor/'
CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_IMAGE_BACKEND = 'pillow'
и мой urls.py как:
"""MyNews URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include, re_path
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
path('admin/', admin.site.urls), # Maps requests starting with 'admin/' to the Django admin site
path('', include('stories.urls')), # Includes URL patterns from the 'stories' app
re_path(r'^ckeditor/', include('ckeditor_uploader.urls')), # Includes URL patterns from the 'ckeditor_uploader' app
] + static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT) # Serves static files from the 'media' directory