跳转到主要内容

一个针对 django.contrib.sites 的扩展,具有域名重定向和基于设置的自动填充 django.contrib.sites.Site 表的功能。

项目描述

https://travis-ci.org/aldryn/aldryn-sites.svg?branch=develop https://img.shields.io/coveralls/aldryn/aldryn-sites.svg

django.contrib.sites 的扩展。

功能

  • 域名重定向:处理从别名域名到主域名的智能重定向。考虑 http/https。

  • 站点自动填充:根据 ALDRYN_SITES_DOMAINS 设置自动填充 django.contrib.sites.Site.domain 中的域名。

安装

  • aldryn_sites 添加到 INSTALLED_APPS

  • aldryn_sites.middleware.SiteMiddleware 添加到 MIDDLEWARE_CLASSES(如果重定向需要智能处理别名域名可能没有自己的有效证书,请将其放置在 djangosecure.middleware.SecurityMiddleware 之前。中间件将拾取来自 django-secureSECURE_SSL_REDIRECT。)

配置 ALDRYN_SITES_DOMAINS

ALDRYN_SITES_DOMAINS = {
    1: {  # matches SITE_ID
        'domain': 'www.example.com',  # main domain that all domains in redirects will redirect to.
                                      # Auto populates ``django.contrib.sites.Site.domain``
        'aliases': [                  # these domains will be accessible like the main domain (no redirect).
            'an.other.domain.com',
            r'^[a-z0-9-]+\.anysub\.com$',  # regexes are supported
        ],
        'redirects': [                # these domains will be redirected to the main domain.
            'example.com',            # add ``'*'`` to redirect all non-main domains to the main one.
            'example.ch',
            'www.example.ch',
            r'^[a-z0-9-]+\.my-redirect-domain\.com$',  # regexes are supported
            r'.*',  # matches any domain (Makes the above rules useless. It's just an example)
        ],
    }
}

当使用正则表达式时

  • 精确匹配优于模式匹配

  • 模式重定向匹配优于模式别名匹配

其他设置

ALDRYN_SITES_SET_DOMAIN_NAME 设置为 False,如果您不想自动填充 django.contrib.sites.Site.domain(默认值:True)。

待办事项

  • 验证设置

  • 测试设置验证器

  • 如果数据库中有不在设置中的站点,记录警告

  • 以简洁的方式显示重定向的工作方式(在管理界面和简单工具中)

  • 对别名支持正则表达式

  • 用于测试重定向逻辑的表单

  • 预编译和缓存正则表达式

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分布

aldryn-sites-0.6.0.tar.gz (7.2 kB 查看哈希值)

上传时间

由以下支持