一个针对 django.contrib.sites 的扩展,具有域名重定向和基于设置的自动填充 django.contrib.sites.Site 表的功能。
项目描述
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-secure 的 SECURE_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 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | d2851341e923e89cd8afaf5a3c108db10182c47bfbf09d0cf5c87578e082e46c |
|
| MD5 | 798b804c3ee732facf67648476c12d0f |
|
| BLAKE2b-256 | 7e57933cdcce7c38bb307a0cfc92dbcdf33dde575989d0481780ec8a772e407f |