Question

I'm new to werkzeug and I'm getting a "TypeError: init() takes at least 2 arguments (1 given)" when I try to visit a test page after installation and setup. Werkzeug does provide a traceback (see below). I've looked at that and my settings without success.

I've installed the following packages:

django_extensions
werkzeug

added the following to my Django settings file:

########## WERKZEUG/DJANGO EXTENSIONS
INSTALLED_APPS += (
    'django_extensions',
    'werkzeug',
)
MIDDLEWARE_CLASSES += (
    'werkzeug.debug.DebuggedApplication',
)
########## END WERKZEUG/DJANGO EXTENSIONS

and created a dev_wsgi.py file that I call from my gunicorn driver script:

# basic wsgi.py
import os

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my-site.settings.dev')

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Werkzeug-specific
import django.views.debug

def null_technical_500_response(request, exc_type, exc_value, tb):
    raise exc_type, exc_value, tb
django.views.debug.technical_500_response = null_technical_500_response

# apply Werkzeug WSGI middleware
from werkzeug.debug import DebuggedApplication
application = DebuggedApplication(application, evalex=True)

But now when I view a test URL, I get the following traceback:

File "/python2-venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
self.load_middleware()
File "/python2-venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 49, in load_middleware
mw_instance = mw_class()
TypeError: __init__() takes at least 2 arguments (1 given)

Commenting out the Werkzeug-specific lines in dev_wsgi.py allows my test page to display correctly. I'm using Werkzeug 0.9.4, django_extensions 1.3.3, django 1.6.4 and Python 2.7.6.

Était-ce utile?

La solution

werkzeug.debug.DebuggedApplication is a WSGI middleware not a Django middleware. Django middleware expect no arguments to the __init__ and are added to MIDDLEWARE_CLASSES. WSGI middleware take at least one argument to the __init__ which is the WSGI application to be wrapped. You are attempting to use it as both but the fix is simple. Remove werkzeug.debug.DebuggedApplication from the MIDDLEWARE_CLASSES setting.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top