Home:ALL Converter>File upload with CKEditor and Django

File upload with CKEditor and Django

Ask Time:2017-03-03T11:38:25         Author:Anh

Json Formatter

I am having trouble with implementing image upload in DJango and CKEditor.

Here is my code: models.py

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

# Create your models here.
class post(models.Model):
    title = models.CharField(max_length=100)
    # body = RichTextField()
    body = RichTextUploadingField('body')
    date = models.DateTimeField()
    image = models.ImageField(upload_to = 'posts/%Y/%m/%d', null=True, blank=True)

    def __str__(self):
        return self.title

urls.py:

from django.conf.urls import url, include
from posts.models import post
from posts import views
from django.conf.urls.static import static
from django.conf import settings

app_name = 'posts'
urlpatterns = [
    url(r'^$', views.IndexView.as_view(), name='index'),
    url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
    url(r'^ckeditor_uploader/', include('ckeditor_uploader.urls')),
] 

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root= settings.MEDIA_ROOT)

Whenever I access Post in Admin, I get this error:

NoReverseMatch at /admin/posts/post/13/change/
Reverse for 'ckeditor_upload' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

It seems like an URL error but I am not sure what went wrong.

Author:Anh,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/42570198/file-upload-with-ckeditor-and-django
yy