python - 如何在django自带的admin后台写博文时插入图片?
伊谢尔伦
伊谢尔伦 2017-04-17 17:22:56
0
3
274

初学django,目前我用django实现了一个很小的blog,但我想在admin后台编辑内容的区域加入插入图片并且预览的功能,不知道该如何实现。恳请大家在这里给我一点实现的思路,小弟感激不尽。

关键代码展示如下:

models.py

class Post(models.Model):
    #some other fields
    title = models.CharField(max_length=70, default='')
    body = models.TextField(default='')#这里就是对应于后台编辑区域的fields

感谢楼下两位朋友的回答,对我很有帮助,部分的插件我也尝试用过。但是因为我目前处于学习django的阶段,因此不想使用任何的第三方包来实现我的需求,而且我也并不需要一个富文本编辑器,只需要一个上传图片的功能就行了。

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(3)
左手右手慢动作

Recommended https://github.com/pydanny/django-wysiwyg plug-in, where you can choose various HTML editors such as: ckeditor, tinymce, etc.
The specific steps are as follows:

  1. INSTALLED_APPS Add django_wysiwyg.

  2. Configure the editor type to be used DJANGO_WYSIWYG_FLAVOR = "ckeditor" #The ckeditor used here

  3. Modify the admin file corresponding to the model, and set the change_form_template of the admin class of the model to 'fun/admin/change_form.html'

  4. Copy: cp django_wysiwyg/templates/my-app-name/admin/change_form.html pydanny/templates/fun/admin/change_form.html

  5. Modify change_form.html file
    {% extends "admin/change_form.html" %}
    {% load wysiwyg %}

    {% block extrahead %}

       {{ block.super }}
       {% wysiwyg_setup %}

    {% endblock %}

    {% block content %}

       {{ block.super }}
       {% wysiwyg_editor "id_description" %}

    {% endblock %}

    Just change "id_description" to the name of the field where your corresponding model needs to use the editor.

Peter_Zhu

django-ckeditor

大家讲道理

https://github.com/summernote/django-summernote

https://github.com/rosarior/awesome-django

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!