Django: Object of type WindowsPath is not JSON serializable

107 Views Asked by At

I am trying to add ckeditor_uploader to my project, and adding posts in django default admin site.
I get the following error:

Error during template rendering in
\venv\lib\sitepackages\django\contrib\admin\templates\admin\change_form.html,
error at line 6
Object of type WindowsPath is not JSON serializable

1   {% extends "admin/base_site.html" %}
2   {% load i18n admin_urls static admin_modify %}
3   
4   {% block extrahead %}{{ block.super }}
5   <script src="{% url 'admin:jsi18n' %}"></script>
6   {{ media }}
7   {% endblock %}

in settings.py

MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / 'media'

CKEDITOR_BASEPATH = BASE_DIR / 'static/ckeditor/ckeditor'
CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'full',
        'height': 300,
        'width': 1300,
    },
}

in models.py

from django.db import models
from ckeditor_uploader.fields import RichTextUploadingField

class Post(models.Model):
    author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
    title = models.CharField(max_length=200)
    category = models.ForeignKey(Category, on_delete=models.CASCADE, default=get_default_category)
    text = RichTextUploadingField(default="add your post here")

I tried adding + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) after urlpatterns in urls.py and got no luck.

1

There are 1 best solutions below

0
On

I had the same issue. I tried to remove CKEDITOR_BASEPATH and it worked.