将代码段插件添加到django cms。
djangocms-snippet的Python项目详细描述
django cms snippet为django CMS提供插件 将html、css或javascript片段插入您的网站。
此加载项与Divio Cloud兼容,也可以在 django CMS Marketplace 便于安装。
我们建议仅在开发期间使用此插件:
This plugin is a potential security hazard, since it allows authorized- users to place custom markup or Javascript on pages bypassing all of Django's normal sanitization mechanisms. This could be exploited by users with the right to add snippets to elevate their privileges to superusers. This plugin should only be used during the initial development phase for rapid prototyping and testing.
贡献
这是一个开源项目。我们很高兴收到您的 以问题和请求的形式提供反馈。在提交您的 拉动请求,请查看我们的contribution guidelines。
我们感谢所有帮助创建和维护此软件包的贡献者。 贡献者列在contributors 章节。
你能做的最简单的贡献之一就是帮助翻译这个插件 Transifex。
文档
参见setup.py中的REQUIREMENTS。 其他依赖项的文件:
安装
对于手动安装:
- 运行pip install djangocms-snippet
- 将djangocms_snippet添加到INSTALLED_APPS
- 运行python manage.py migrate djangocms_snippet
配置
若要允许搜索所有代码段的内容,请设置 DJANGOCMS_SNIPPET_SEARCH到True在您的设置中:
DJANGOCMS_SNIPPET_SEARCH = True
我们正在使用Ace作为我们选择的编辑器 编辑代码段内容。您可以自定义 theme和 mode到:
DJANGOCMS_SNIPPET_THEME = 'github' DJANGOCMS_SNIPPET_MODE = 'html'
模板标签
您还可以使用模板标记来呈现片段,而不是插件:
{% load snippet_tags %} {% snippet_fragment [reference] %}
将[reference]替换为:
- 代码段ID,例如{% snippet_fragment 42 %}
- 片段slug,例如{% snippet_fragment 'my-snippet' %}
- 代码段实例,例如{% snippet_fragment instance.snippet %}
如果没有匹配的id/slug/instance:
{% snippet_fragment 'my-snippet' or %} ... your content fallback here ... {% endsnippet_fragment %}
运行测试
您可以执行以下操作来运行测试:
virtualenv env source env/bin/activate pip install -r tests/requirements.txt python setup.py test