集成Quill编辑器和Django项目。
django-quill-editor的Python项目详细描述
django鹅毛笔编辑
django quill editor使Quill.js易于在django表单和管理站点上使用
- 静态文件不需要配置!
- 插入所见即所得编辑器的整个代码不到30行
- 它可以在admin和Django视图中使用
设置
- 在
将
django-quill-editor
安装到Python环境中pip install django-quill-editor
在 - 在
将
^{pr2}$ 在django_quill
添加到settings.py
中的INSTALLED_APPS
运行示例项目
# Clone repo git clone https://github.com/LeeHanYeong/django-quill-editor-sample cd django-quill-editor-sample # Create virtualenv (I used pyenv, but you can use other methods) pyenv virtualenv 3.7.5 django-quill pyenv local django-quill # Install Python packages pip install -r requirements.txt python app/manage.py runserver
文件
django quill editor的文档位于https://django-quill-editor.readthedocs.io/
更改工具栏配置
将QUILL_CONFIGS
添加到设置.py
QUILL_CONFIGS={'default':{'theme':'snow','modules':{'syntax':True,'toolbar':[[{'font':[]},{'header':[]},{'align':[]},'bold','italic','underline','strike','blockquote',{'color':[]},{'background':[]},],['code-block','link'],['clean'],]}}}
使用
将QuillField
添加到要使用的Model类
# models.pyfromdjango.dbimportmodelsfromdjango_quill.fieldsimportQuillFieldclassQuillPost(models.Model):content=QuillField()
1。Django管理员
只需在^{str 1}中注册模型$管理员py。在
fromdjango.contribimportadminfrom.modelsimportQuillPost@admin.register(QuillPost)classQuillPostAdmin(admin.ModelAdmin):pass
2。表格
- 在
将
在QuillFormField
添加到要使用的Form类 - 在
有两种方法可以将CSS和JS文件添加到模板中。在
- 在
如果有一个添加了QuillField的^{str1}$Form,请将
{{ form.media }}
添加到<head>
标记中。在<head>{{form.media}}</head>
在 - 在
或者,直接使用
{% include %}
模板标记导入CSS和JS文件。在<head> <!-- django-quill-editor Media -->{%include'django_quill/media.html'%}</head>
在
- 在
# forms.pyfromdjangoimportformsfromdjango_quill.formsimportQuillFormFieldclassQuillFieldForm(forms.Form):content=QuillFormField()
# views.pyfromdjango.shortcutsimportrenderfrom.formsimportQuillFieldFormdefform(request):returnrender(request,'form.html',{'form':QuillFieldForm()})
<!-- Template --><form action="" method="POST">{%csrf_token%}{{form.content}}</form>
3。模型形式
只需定义并使用模型类的ModelForm
# forms.pyfromdjangoimportformsfrom.modelsimportQuillPostclassQuillPostForm(forms.ModelForm):classMeta:model=QuillPostfields=('content',)
# views.pyfromdjango.shortcutsimportrenderfrom.formsimportQuillPostFormdefmodel_form(request):returnrender(request,'model_form.html',{'form':QuillPostForm()})
<!-- Template --><form action="" method="POST">{%csrf_token%}{{form.content}}</form>
Form,ModelForm的输出:
贡献
作为一个开源项目,我们欢迎贡献。 代码存在于GitHub
分配(业主)
PyPI发布
poetry install # Install PyPI distribution packages
python deploy.py
斯芬克斯文件
brew install sphinx-doc # macOS
本地
cd docs
make html
# ...
# The HTML pages are in _build/html.
cd _build/html
python -m http.server 3001
- 项目
标签: