每个django应用程序都需要的常见功能!
django-common-tivix的Python项目详细描述
概述
django common包含以下内容:
- A middleware that makes sure your web-app runs either on or without ‘www’ in the domain.
- A ^{tt1}$ base class, that helps in keeping your session related code object-oriented and clean! See session.py for usage details.
- An ^{tt2}$ for authenticating users based on their email, apart from username.
- Some custom db fields that you can use in your models including a ^{tt3}$ and ^{tt4}$.
- Bunch of helpful functions in helper.py
- A ^{tt5}$ template tag that makes rendering form fields easy and DRY.
- A couple of dry response classes: ^{tt6}$ and ^{tt7}$ in the django_common.http that can be used in views that give json/xml responses.
安装
安装django_common(最好是在您的virtualenv中!)使用pip或者简单地获取代码的副本并将其放在代码库的目录中。
将django_common添加到django设置中INSTALLED_APPS:
INSTALLED_APPS = [ # ... "django_common", ]
使用适当的值将以下内容添加到settings.py中:
- IS_DEV
- IS_PROD
- DOMAIN_NAME
- WWW_ROOT
将common_settings添加到django设置中TEMPLATE_CONTEXT_PROCESSORS:
TEMPLATE_CONTEXT_PROCESSORS = [ # ... "common_settings", ]
将EmailBackend添加到django设置AUTHENTICATION_BACKENDS:
AUTHENTICATION_BACKENDS = ( 'django_common.auth_backends.EmailBackend', 'django.contrib.auth.backends.ModelBackend' )
如果需要,请将WWWRedirectMiddleware添加到中间产品列表:
MIDDLEWARE_CLASSES = [ # ... "WWWRedirectMiddleware", ]
这个开源应用程序是由tivix,inc.(http://tivix.com/)提供给您的。