用于将页面生成器“grapesjs”集成到django管理中的小型库
django-grapesjs的Python项目详细描述
安装
pip install django_grapesjs
然后将其添加到已安装的应用程序中:
INSTALLED_APPS=('django_grapesjs',...'django.contrib.admin',)
要使用“template_choices”,需要在urls.py文件中添加一个url模板
urlpatterns=[path('get_template/',GetTemplate.as_view(),name='dgjs_get_template'),]
使用
只需导入字段并将其添加到模型中即可
fromdjango.dbimportmodelsfromdjango_grapesjs.modelsimportGrapesJsHtmlFieldclassExampleModel(models.Model):html=GrapesJsHtmlField()...# default_html - path to the html file to display the default value# for the field when the form page is receivedhtml=GrapesJsHtmlField(default_html='default.html')# or default - if the page is simply statichtml=GrapesJsHtmlField(default=render_to_string('default.html'))...# use the redactor_config argument to select the configuration of the editor# Available:# - redactor_config='base' - basic setting, most widgets are used# - redactor_config='min' - minimum setting, only the most necessaryhtml=GrapesJsHtmlField(redactor_config='base')...# use apply_django_tag = True, if you want to apply render django or jinja tagshtml=GrapesJsHtmlField(default_html='default.html',apply_django_tag=True)...# use template_choices to select multiple templateshtml=GrapesJsHtmlField(template_choices=(('django_grapesjs/default.html','default'),))
然后继承当前模型
的管理类中的“pULSeJSADMIN MIXIN”fromdjango.contribimportadminfromdjango_grapesjs.adminimportGrapesJsAdminMixin@admin.register(ExampleModel)classExampleAdmin(GrapesJsAdminMixin,admin.ModelAdmin):pass
您可以在模板中使用特殊标记,用于灵活定制
<ignore></ignore>
如果在保存过程中需要注释掉一些html代码, 但在页面生成器中编辑时执行或显示-使用此标记。 例如,如果使用django或jinja标记的模板没有任何样式或javascript (因为它们在另一个地方,例如在“footer.html”中),您可以将css和js放在 编辑器中的标记、样式和javascript代码将起作用,但在网站上保存和使用时 不会重复片段
<hidden></hidden>
如果在编辑器中使用apply_django_标记进行编辑,您可能会被附加的: {%exclude%}、{%include%}、{%for<;expression>;%}等-使用此标记。他暂时躲藏起来 在编辑和保存过程中嵌入的信息将返回到原始表单
自定义设置
# True if you want to save html and cssGRAPESJS_SAVE_CSS=False# default value# use the value of the field from the db - True, or use the global save editorGRAPESJS_DEFAULT_MODELS_DATA=True# default value# redefine the path to the html file, the markup from this file will be used by defaultGRAPESJS_DEFAULT_HTML='django_grapesjs/default.html'# default value# Add or redefine the configuration of the editorREDACTOR_CONFIG={'base':'django_grapesjs/redactor_config/base.html'}# default value
警告
库不能在“inlines”中工作