我在DJango和CKEditor中实现图片上传时遇到了麻烦。
这是我的代码: 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)
每当我在Admin中访问Post时,都会收到此错误:
NoReverseMatch at /admin/posts/post/13/change/
Reverse for 'ckeditor_upload' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
这似乎是一个网址错误,但我不确定出了什么问题。
答案 0 :(得分:0)
删除网址(r'^ ckeditor_uploader /',include('ckeditor_uploader.urls')), 添加到ckeditor_uploader - &gt; CKEditor的
urlpatterns = [
**url(r'^ckeditor/', include(ckeditor_uploader_urls)),**
]