Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: ModuleNotFoundError 'No module named django.core.urlresolvers… #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@
build/
dist/
pip-log.txt
venv/*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
18 changes: 12 additions & 6 deletions subdomains/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@

from subdomains.utils import get_domain


logger = logging.getLogger(__name__)
lower = operator.methodcaller('lower')

UNSET = object()

try:
from django.utils.deprecation import MiddlewareMixin
except:
MiddlewareMixin = object


class SubdomainMiddleware(object):
class SubdomainMiddleware(MiddlewareMixin):
"""
A middleware class that adds a ``subdomain`` attribute to the current request.
"""

def get_domain_for_request(self, request):
"""
Returns the domain that will be used to identify the subdomain part
Expand All @@ -30,7 +35,7 @@ def process_request(self, request):
Adds a ``subdomain`` attribute to the ``request`` parameter.
"""
domain, host = map(lower,
(self.get_domain_for_request(request), request.get_host()))
(self.get_domain_for_request(request), request.get_host()))

pattern = r'^(?:(?P<subdomain>.*?)\.)?%s(?::.*)?$' % re.escape(domain)
matches = re.match(pattern, host)
Expand All @@ -40,14 +45,15 @@ def process_request(self, request):
else:
request.subdomain = None
logger.warning('The host %s does not belong to the domain %s, '
'unable to identify the subdomain for this request',
request.get_host(), domain)
'unable to identify the subdomain for this request',
request.get_host(), domain)


class SubdomainURLRoutingMiddleware(SubdomainMiddleware):
"""
A middleware class that allows for subdomain-based URL routing.
"""

def process_request(self, request):
"""
Sets the current request's ``urlconf`` attribute to the urlconf
Expand All @@ -62,7 +68,7 @@ def process_request(self, request):
urlconf = settings.SUBDOMAIN_URLCONFS.get(subdomain)
if urlconf is not None:
logger.debug("Using urlconf %s for subdomain: %s",
repr(urlconf), repr(subdomain))
repr(urlconf), repr(subdomain))
request.urlconf = urlconf

def process_response(self, request, response):
Expand Down
2 changes: 1 addition & 1 deletion subdomains/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
except ImportError: # Python 3
from urllib import parse as urlparse

from django.core.urlresolvers import NoReverseMatch, set_urlconf
from django.urls import NoReverseMatch, set_urlconf
from django.template import Context, Template
from django.test import TestCase
from django.test.client import RequestFactory
Expand Down
2 changes: 1 addition & 1 deletion subdomains/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from urllib.parse import urlunparse

from django.conf import settings
from django.core.urlresolvers import reverse as simple_reverse
from django.urls import reverse as simple_reverse


def current_site_domain():
Expand Down