TypeError: 'module' object is not callable

1,192 views
Skip to first unread message

db_333

unread,
Jun 19, 2009, 6:38:40 PM6/19/09
to Django users
Hi,

I am new to Django and am trying to create a simple form around an
existing database (I'm using 1.0). The Model I have looks like this:

class Units(models.Model):
serial_number = models.CharField(max_length=25, primary_key=True)
build = models.CharField(max_length=50, blank=True)
model = models.CharField(max_length=20, blank=True)
create_date = models.DateField(null=True, blank=True)
source = models.CharField(max_length=20, blank=True)
class Meta:
db_table = u'units'

In my view, I created this function:
def save_unit(request):
if request.method == 'POST':
form = UnitFormSave(request.POST)
if form.is_valid():
unit = Units.objects.create(
serial_number = form.clean_data['serial_number'],
build = form.clean_data['build'],
model = form.clean_data['model'],
source = form.clean_data['source'])
unit.save(force_insert=True)
return HttpResponseRedirect('/search/')
else:
form = UnitFormSave()

variables = RequestContext(request, {
'form': form
})
return render_to_response('unit_save.html', variables)

The form:
class UnitFormSave(forms.Form):
serial_number = forms.CharField(max_length=50)
build = forms.CharField(max_length=50)
model = forms.CharField(max_length=10)
source = forms.CharField(max_length=10)

Unfortunately I getting this error and can't seem to get any detail
from some of the debugging. I know the answer is probably right in
front of me, but I can't see where I went wrong. I'm getting this
error from the server output:

Traceback (most recent call last):
File "/Library/Python/2.5/site-packages/django/core/servers/
basehttp.py", line 278, in run
self.result = application(self.environ, self.start_response)
File "/Library/Python/2.5/site-packages/django/core/servers/
basehttp.py", line 635, in __call__
return self.application(environ, start_response)
File "/Library/Python/2.5/site-packages/django/core/handlers/
wsgi.py", line 228, in __call__
self.load_middleware()
File "/Library/Python/2.5/site-packages/django/core/handlers/
base.py", line 47, in load_middleware
mw_instance = mw_class()
TypeError: 'module' object is not callable
[19/Jun/2009 14:09:22] "GET / HTTP/1.1" 500 644

Alex Gaynor

unread,
Jun 19, 2009, 7:17:11 PM6/19/09
to django...@googlegroups.com
The issue is with something in your middleware, specifically you have something in your MIDDLEWARE setting that doesn't point to an actual class.

Alex

--
"I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire
"The people's good is the highest law."--Cicero

Andy McKay

unread,
Jun 19, 2009, 7:20:08 PM6/19/09
to django...@googlegroups.com

On 19-Jun-09, at 3:38 PM, db_333 wrote:
> File "/Library/Python/2.5/site-packages/django/core/handlers/
> wsgi.py", line 228, in __call__
> self.load_middleware()
> File "/Library/Python/2.5/site-packages/django/core/handlers/
> base.py", line 47, in load_middleware
> mw_instance = mw_class()
> TypeError: 'module' object is not callable
> [19/Jun/2009 14:09:22] "GET / HTTP/1.1" 500 644

But what Middleware do you have installed - whats the settings.py
value for middleware?

It looks like that might be problem, none of the above code.

db_333

unread,
Jun 19, 2009, 7:24:39 PM6/19/09
to Django users
here's what I have for the Middleware:

MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.models'
)
I'm searching the APIs to see what I might be missing... any
pointers?

Alex Gaynor

unread,
Jun 19, 2009, 7:25:45 PM6/19/09
to django...@googlegroups.com
Why did you add 'django.contrib.auth.models' to your middleware?  That's whats causing your issue, but what were you hoping to accomplish?

db_333

unread,
Jun 19, 2009, 7:32:49 PM6/19/09
to Django users
I wanted to later implement a login based on a user session, and I got
some guidance from pretty decent Django book on learning to build
websites with Django. However, I can see that I need to better
understand how the middleware APIs work before I jump ahead.
I appreciate your quick responses

On Jun 19, 4:25 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:

Paula Leuzzi

unread,
Jun 23, 2009, 8:33:48 PM6/23/09
to Django users
Is there any way to tell through debugging if there's an issue with saving a record?  This form seems to work fine, but the record does not save.  I'm lost as to why it's not committing.  Any pointers on debug statements for this kind of issue?
Reply all
Reply to author
Forward
0 new messages