django 二级子域名配置

例如:wap.test.com

1 写一中间件

class SubdomainMiddleware(object):
    def process_request(self, request):
        domain_parts = request.get_host().split('.')
        if len(domain_parts) == 3 and domain_parts[0] != 'www':

            request.path_info = '/%s%s' % (domain_parts[0], request.path)

2 加入settings.py 的中间件配置里

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'test.base.middlewares.SubdomainMiddleware',
    ...}

over...


莽荒纪

你可能感兴趣的:(django,二级域名)