django-subdomains icon indicating copy to clipboard operation
django-subdomains copied to clipboard

Middleware fails with Django 1.10

Open huwshimi opened this issue 9 years ago • 12 comments
trafficstars

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

huwshimi avatar Aug 03 '16 12:08 huwshimi

I have the same issue. Sadly.

cataclysmic avatar Sep 24 '16 03:09 cataclysmic

Please fix this issue, u might need a init function in your middleware.py

vinitapplop avatar Sep 29 '16 11:09 vinitapplop

I also came across this issue

ArsenSim avatar Oct 13 '16 16:10 ArsenSim

I am also having this issue

al-alamin avatar Feb 06 '17 19:02 al-alamin

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.

parth-choudhary avatar Mar 23 '17 14:03 parth-choudhary

the solution /parth-choudhary provided worked perfectly for django 1.10! Thanks alot dude, saved me some time.

JohnRipper avatar Apr 11 '17 17:04 JohnRipper

using MIDDLEWARE_CLASSES instread of MIDDLEWARE solve the issue in mine.

awemulya avatar May 17 '17 10:05 awemulya

MIDDLEWARE_CLASSES is deprecated since django 1.10 I believe. The best option would be parth-choudhary's.

ghost avatar Jun 23 '17 19:06 ghost

Any workaround for this problem? MIDDLEWARE_CLASSES and MIDDLEWARE can not be used together.

krdeepak avatar Jul 10 '17 14:07 krdeepak

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.

parth-choudhary avatar Jul 10 '17 17:07 parth-choudhary

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

pmaigutyak avatar Oct 20 '17 11:10 pmaigutyak

I use django 1.11.5 with nginx configuration but is not working correctly the subdomain

Allan-Nava avatar Oct 12 '18 09:10 Allan-Nava