question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Middleware fails with Django 1.10

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:6
  • Comments:12

github_iconTop GitHub Comments

17reactions
parth-choudharycommented, Mar 23, 2017

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.

4reactions
parth-choudharycommented, Jul 10, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Middleware - Django documentation
This document explains how middleware works, how you activate middleware, and how to write your own middleware. Django ships with some built-in middleware...
Read more >
Django 1.10.6 - Middleware does not work - Stack Overflow
You can do old style middlewares by inheriting django.utils.deprecation.MiddlewareMixin like class OldMiddleware(MiddlewareMixin): #rest of ...
Read more >
Custom Middleware Issue with Mezzanine/Cartridge
So I tried switching to the function-based middleware from the django docs: https://docs.djangoproject.com/en/1.10/topics/http/middleware/.
Read more >
Getting started with Django middleware
First, create a Django project with a single application. Ignore the migrations, examples from this post will not use a database. Create a...
Read more >
Custom settings and wsgi in django 1.10 give me error-django
I tried directly in Django 1.10! Initially it showed "TypeError: object() takes no parameters" error. After I changed MIDDLEWARE to MIDDLEWARE_CLASSES in my ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found