django-subdomains
django-subdomains copied to clipboard
Middleware fails with Django 1.10
If I use the SubdomainURLRoutingMiddleware middleware with the new MIDDLEWARE = [...] setting then any view fails with:
Traceback (most recent call last):
File "/home/username/project/test_file.py", line 353, in test_file
HTTP_HOST='subdomain.example.com'
File "/home/username/project/env/local/lib/python2.7/site-packages/django/test/client.py", line 541, in post
secure=secure, **extra)
File "/home/username/project/env/local/lib/python2.7/site-packages/django/test/client.py", line 343, in post
secure=secure, **extra)
File "/home/username/project/env/local/lib/python2.7/site-packages/django/test/client.py", line 409, in generic
return self.request(**r)
File "/home/username/project/env/local/lib/python2.7/site-packages/django/test/client.py", line 476, in request
response = self.handler(environ)
File "/home/username/project/env/local/lib/python2.7/site-packages/django/test/client.py", line 129, in __call__
self.load_middleware()
File "/home/username/project/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 82, in load_middleware
mw_instance = middleware(handler)
TypeError: object() takes no parameters
I believe the middleware may need updating to be compatible with Django 1.10: https://docs.djangoproject.com/en/1.10/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware
I have the same issue. Sadly.
Please fix this issue, u might need a init function in your middleware.py
I also came across this issue
I am also having this issue
The issue is resolved by replacing
class SubdomainMiddleware(object):
with
try:
from django.utils.deprecation import MiddlewareMixin
except ImportError:
MiddlewareMixin = object
class SubdomainMiddleware(MiddlewareMixin):
in the middleware.py file. I can open a Pull request to fix this issue if needed.
the solution /parth-choudhary provided worked perfectly for django 1.10! Thanks alot dude, saved me some time.
using MIDDLEWARE_CLASSES instread of MIDDLEWARE solve the issue in mine.
MIDDLEWARE_CLASSES is deprecated since django 1.10 I believe. The best option would be parth-choudhary's.
Any workaround for this problem? MIDDLEWARE_CLASSES and MIDDLEWARE can not be used together.
You can use the fork I created, just install it using:
pip install git+https://github.com/parth-choudhary/django-subdomains.git
Should work fine.
I've created my own middleware class
from django.utils.deprecation import MiddlewareMixin
from subdomains.middleware import SubdomainURLRoutingMiddleware
class SubdomainMiddleware(MiddlewareMixin, SubdomainURLRoutingMiddleware):
pass
That solved the problem
I use django 1.11.5 with nginx configuration but is not working correctly the subdomain