Django的简单Fancybox模态框
项目描述
安装
pip install django-fancybox
外部依赖项
jQuery - 由于在大多数情况下预期该软件包已经可用,因此不包括在内。
设置
将 fancybox 添加到 INSTALLED_APPS
INSTALLED_APPS += (
'fancybox',
)
确保您有 django.template.context_processors.request 处理器
TEMPLATES = [
{
...
'OPTIONS': {
'context_processors': [
...
'django.template.context_processors.request',
],
},
},
]
并仅包含 fancybox 模板
{% include "fancybox/fancybox_css.html" %} {# Before the closing head tag #}
{% include "fancybox/fancybox_js.html" %} {# Before the closing body tag #}
在生产服务器上部署时,别忘了运行
python manage.py collectstatic
用法
扩展ajax请求的基本模板
{% extends request.is_ajax|yesno:"fancybox/base.html,base.html" %}
将 class="fancybox" 添加到链接,并将href设置为要显示的页面
<a data-fancybox data-type="ajax" href="{% url 'remote.html' %}" class="fancybox">Click here</a>
请参阅 example 应用程序。该应用程序用于手动测试此包的功能。它也是一个很好的例子。
您只需要Django 1.4或更高版本即可运行它。它可能在旧版本上运行,但没有经过测试。
许可证
django-fancybox 根据BSD许可证发布。