提供对垃圾邮件发送者和骗子的保护。
django-secureform的Python项目详细描述
一个SmartFile开源项目。Read more关于smartfile如何 使用和贡献开源软件
简介
提供对垃圾邮件发送者和骗子的保护。
安装
使用pip安装django secureform
然后在settings.py中将应用程序安装到django项目中。也有可选设置 这将影响SecureForm实例的行为
INSTALLED_APPS += ('django_secureform', ) # If you wish to use an encryption key other than Django's SECRET_KEY SECUREFORM_CRYPT_KEY = 'super-secret encryption key' # This is the name of the hidden field added to the form to contain # security data. SECUREFORM_FIELD_NAME = 'foobar' # The number of seconds allowed between form rendering and submittal. SECUREFORM_TTL = 300 # The number of honeypot fields added to the form. SECUREFORM_HONEYPOTS = 1 # By default, jQuery is needed to hide honeypots. If you already # use jQuery in your app, you can disable this feature (preventing # a duplicate script reference to jQuery). SECUREFORM_INCLUDE_JQUERY = False
用法
from django_secureform.forms import SecureForm # Define your form class as usual. class MySecureForm(SecureForm): class Meta: # Override options in settings.py for this class. include_jquery = False name = forms.CharField()
单元测试
如果要为从SecureForm派生的窗体编写单元测试,则 需要让这个应用程序知道您正在测试。SecureForm查找 设置。测试以评估为真。如果是,它将禁用 django测试客户机使用原始字段名发送post数据。
在将来,我更愿意提供工具,这样测试就可以在 启用了安全性,但这是一个快速的解决方法我们的测试框架使用 用于设置settings.testing的环境变量。例如,在settings.py…
import os TESTING = True if 'TESTING' in os.environ else False