2
我已將ckeditor應用於blog_description字段,其中包含RichTextUploadingField
。瀏覽服務器按鈕,僅顯示縮略圖
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),
]
但是當我點擊瀏覽服務器按鈕,它問:「選擇圖像,然後單擊‘嵌入圖像’按鈕繼續..」並沒有任何按鈕。
任何人都可以請幫助我,我將如何設置正確的路徑,或者我錯過了什麼代碼來顯示圖像。
你的設置清楚地顯示了「不會」的字符錯誤,這是這裏還是你的代碼中的錯字? 'AWS_QUERYSTRING_AUTH = False //我猜這不適用於django' – Sayse
你在哪裏託管這些圖片? –
我已託管圖片以在media_cdn內「上傳」文件夾。而那個錯字,我想提到「我已經添加了AWS ...但它不會與Django一起工作」。 我認爲我在定義路徑時犯了錯誤。 – Sagar