Django Ckeditor图像浏览器找不到图像 [英] Django Ckeditor image browser not finding images

查看:570
本文介绍了Django Ckeditor图像浏览器找不到图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在建立一个简单的博客来跟踪我的项目。我决定用CKeditor作为wysiwyg编辑器。我能够把它所有的工作,除了它的图像部分。当我点击图像浏览时,我无法查看服务器中的图像,每当我上传图像时,它都会上传,但无法查看。它会弹出一个红色的'X'。

So I'm building a simple blog to keep track of my projects. I decided to use CKeditor as the wysiwyg editor. I was able to get all of it to work except for the image portion of it. I'm not able to view the images in the server when I hit "image browse", and whenever I upload an image, it does upload but I can't view it. It pops up as a red 'X'.

链接截图显示发生的情况: http:// imgur .com / a / ODk8p

Link to screenshots showing what's happening: http://imgur.com/a/ODk8p

以下是我将CKEditor添加到我安装的应用程序的代码。我的项目的 settings.py

Below is the code I have where I added CKEditor to my installed apps my project's settings.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'projects',
    'ckeditor',
)

稍后在我的项目的 中我有CKEditor的设置:

Later in my project's settings.py I have the setup for CKEditor:

MEDIA_ROOT = os.environ.get('MEDIA_ROOT',os.path.join(BASE_DIR, 'media'))
MEDIA_URL = '/media/'

CKEDITOR_UPLOAD_PATH   = "uploads/"
CKEDITOR_UPLOAD_SLUGIFY_FILENAME = False
CKEDITOR_RESTRICT_BY_USER = True
CKEDITOR_JQUERY_URL = 'http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'
CKEDITOR_CONFIGS = {
    'default': {
        'removePlugins': 'stylesheetparser',
        'toolbar': 'Full',
        'height': 500,
        'width': 900,
    },
}

这是我的项目的models.py (现在看起来很简单):

Here is my models.py for my project (looking very simple for now):

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

class Project(models.Model):
    title = models.CharField(max_length=300)
    banner = models.ImageField(upload_to='banners/')
    body = RichTextField(config_name='default')
    version = models.CharField(max_length=140)

    def __str__():
        return self.title

我也有这一行在我的项目的

I also have this line to add CKEditor url in my project's urls.py:

url(r'^ckeditor/', include('ckeditor.urls')),



任何想法可能是错误的?除了图像之外,一切都起作用。
任何帮助是非常感激的

Any idea as to might be wrong? Everything works except for the images. Any Help is strongly appreciated

推荐答案

如果这是DEBUG / runserver模式,你还记得添加<从django.conf导入设置

If this is in DEBUG/runserver mode, did you remember to add

from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

if settings.DEBUG:
    urlpatterns += patterns(
        '',
        url(
            r'^media/(?P<path>.*)$',
            'django.views.static.serve', {
                'document_root': settings.MEDIA_ROOT,
            }
        ),
    )

urlpatterns += staticfiles_urlpatterns()

到您的 urls.py

这篇关于Django Ckeditor图像浏览器找不到图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆