一组独立于项目的可重用特性。
django-aloha-editor的Python项目详细描述
django aloha编辑器是所有django支持的网站的所见即所得编辑器。 默认情况下,它总是使用最新版本的aloha编辑器http://aloha-editor.org/
工作原理
django aloha editor检查用户权限,使用aloha editor包装内容<;div>;和 使用ajax调用保存编辑的内容。
安装
pip install django aloha编辑器
将以下URL添加到项目的url s.py文件:
^{tt1}$
将aloha_editor添加到INSTALLED_APPS设置中,以便django可以找到 与aloha编辑器关联的模板文件和模板标记。
示例
视图.py
fromdjango.shortcutsimportrender_to_responsefrombooks.modelsimportBookdefbook_detail(request,book_id):try:book=Book.objects.get(pk=book_id)exceptBook.DoesNotExist:raiseHttp404returnrender_to_response('book_detail.html',{'book':book})
book_detail.html
{% load aloha_editor %} <html><head> {% if user.is_authenticated %} {% include "aloha_editor/css.html" %} {% include "aloha_editor/js.html" %} {% endif %} </head><body><h1>{{ book.title }}</h1> {% aloha_editor book.description %} </body></html>