简体   繁体   English

如何在 django 中使用 ckeditor 上传图像?

[英]How to upload image using ckeditor in django?

models.py模型.py

class Post(models.Model):
    author = models.ForeignKey('auth.User')
    title = models.CharField(max_length=200)
    text = RichTextUploadingField()
    created_date = models.DateTimeField(default=timezone.now)
    published_date = models.DateTimeField(blank=True, null=True)

url.py网址.py

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/login/$', views.login, name='login'),
    url(r'^accounts/logout/$', views.logout, name='logout', kwargs={'next_page': '/'}),
    url(r'^ckeditor/', include('ckeditor_uploader.urls')),
    url(r'', include('blog.urls')),
]
# serving media files only on debug mode
if settings.DEBUG:
    urlpatterns += [
        url(r'^media/(?P<path>.*)$', serve, {
            'document_root': settings.MEDIA_ROOT
        }),
    ]

I will upload image using CKeditor.我将使用 CKeditor 上传图像。 There is no error.没有错误。 However, it looks like a picture.然而,它看起来像一张照片。

图片

When rendering html in templates, make sure you mark it as safe...在模板中渲染 html 时,请确保将其标记为安全...

{{ article.text|safe }}

See documentation:请参阅文档:

https://docs.djangoproject.com/en/1.7/ref/templates/builtins/#safe https://docs.djangoproject.com/en/1.7/ref/templates/builtins/#safe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM