浏览服务器按钮,仅显示缩略图

时间:2017-02-07 07:02:41

标签: python django

我已将ckeditor应用于RichTextUploadingField的blog_description字段。

class BlogModel(models.Model):

    blog_title = models.CharField(max_length=255)
    blog_image = models.ImageField(upload_to="images/")
    blog_description = RichTextUploadingField(null=True,blank=True)
    created_date = models.DateTimeField(default=timezone.now)
    published_date = models.DateTimeField(blank=True, null=True)
    category = models.ForeignKey(BlogCategoryModel,to_field='category', default="--Select--")

    def publish(self):
        self.published_date = timezone.now()
        self.save()

    def __str__(self):
        return  self.blog_title

在settings.py文件中,我根据django-ckeditor docs

提到了几乎所有内容
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))    

LOGIN_REDIRECT_URL = '/' # It means home view


DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # third party
    'crispy_forms',
    'markdown_deux',
    'pagedown',
    'ckeditor',
    'ckeditor_uploader',

    # local apps
    'amcapp',
]


MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]


ROOT_URLCONF = 'amcsite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'amcsite.wsgi.application'



DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'amc_databasenew',
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
        'PORT': '3306',
    }
}



AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

AWS_QUERYSTRING_AUTH = False # I guess this won't work with django

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(os.path.join(BASE_DIR), "media_cdn")


CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'

CKEDITOR_UPLOAD_PATH = os.path.join(os.path.join(BASE_DIR), "media_cdn/upload")

CKEDITOR_RESTRICT_BY_USER = True

CKEDITOR_BROWSE_SHOW_DIRS = True

CKEDITOR_UPLOAD_SLUGIFY_FILENAME = False

CKEDITOR_IMAGE_BACKEND = "pillow"

CKEDITOR_UPLOAD_SLUGIFY_FILENAME = True


CKEDITOR_CONFIGS = { 
            'default': { 
                'toolbar': [
                    ["Format", "Bold", "Italic", "Underline", "Strike", "SpellChecker", "TextColor", "BGColor"],
                    ['NumberedList', 'BulletedList', "Indent", "Outdent", 'JustifyLeft', 
                    'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
                    ["Image", "Update", "Table", "Link", "Unlink", "Anchor", "SectionLink", "Subscript", "Superscript", "SpecialChar" ], 
                    ['Undo', 'Redo'], 
                    ["Source"],
                    ["Maximize"]],
                # 'toolbar' : 'Full',
                'width': "100%", 
                'height': "100%", 

                enter image description here
                }, 

            }

AWS_QUERYSTRING_AUTH = False - 我想这不应该添加,但只是搜索并尝试,如果它的工作原理。但仍然没有工作

在urls.py中

urlpatterns = [
url(r'', include("amcapp.urls")),
url(r'^ckeditor/', include('ckeditor_uploader.urls')),
url(r'^admin/', admin.site.urls),
]

但是当我点击浏览服务器按钮时,它会询问'选择图像并单击“嵌入图像”按钮继续..'只显示缩略图而没有任何按钮。

after clicking browse server button

有谁可以帮助我如何设置正确的路径或我缺少的代码来显示图像。

1 个答案:

答案 0 :(得分:0)

解决了它。 CKEDITOR_UPLOAD_PATH未正确设置。设置正确的路径后,它工作正常。