Module not callable (Practical Django Projects)

814 views
Skip to first unread message

marsii

unread,
Aug 24, 2008, 7:48:33 AM8/24/08
to Django users
Hi!
I working whit the book Practical Django Project and have a problem
with th weblog example.

(I have Django revision 8511.

I got the following error when I try to add an entry:
---------------------------------------------------
TypeError at /admin/coltrane/entry/add/

'module' object is not callable

Request Method: POST
Request URL: http://127.0.0.1:8000/admin/coltrane/entry/add/
Exception Type: TypeError
Exception Value:

'module' object is not callable

Exception Location: /home/markku/django/practical_djproj/coltrane/
models.py in save, line 76
Python Executable: /usr/bin/python
Python Version: 2.5.2
---------------------------------------------------

copy of my models.py (error line 76 is marked):

---------------------------------------------------
import datetime
from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin
from markdown import markdown
from tagging.fields import TagField

class Category(models.Model):
description = models.TextField()
slug = models.SlugField(unique=True, help_text="Must be unique")

title = models.CharField(max_length=250, help_text='Max 250
chars')

class Meta:
ordering = ['title']
verbose_name_plural = "Categories"

def __unicode__(self):
return self.title

def get_absolute_url(self):
return "/categories/%s/" % self.slug

class CategoryAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ('title',)}

admin.site.register(Category, CategoryAdmin)

class Entry(models.Model):

LIVE_STATUS = 1
DRAFT_STATUS = 2
HIDDEN_STATUS = 3
STATUS_CHOICES = (
(LIVE_STATUS, 'Live'),
(DRAFT_STATUS, 'Draft'),
(HIDDEN_STATUS, 'Hidden'),
)

# Core fields
title = models.CharField(max_length=250, help_text="Max 250
chars")
excerpt = models.TextField(blank=True, help_text="Short sum.
Optional")

body = models.TextField()
pub_date = models.DateTimeField(default=datetime.datetime.now)

# Fields to store genereted HTML
body_html = models.TextField(editable=False, blank=True)
excerp_html = models.TextField(editable=False, blank=True)

# Metadata
author = models.ForeignKey(User)
enable_comments = models.BooleanField(default=True)
featured = models.BooleanField(default=False)
slug = models.SlugField(unique_for_date='pub_date',
help_text="Auto")
status = models.IntegerField(choices=STATUS_CHOICES,
default=LIVE_STATUS,
help_text="Only LIVE will be
pub.displayed")

# Categorization
categories = models.ManyToManyField(Category)
tags = TagField(help_text="Separate tags with spaces")

class Meta:
ordering = ['-pub_date']
verbose_name_plural = "Entries"

def __unicode__(self):
return self.title

def save(self):
self.body_html = markdown(self.body) <-- LINE 76 ERROR
if self.excerpt:
self.excerpt_html = markdown(self.excerpt)
super(Entry, self).save()

def get_absolute_url(self):
return "/weblog/%s/%s/" % (self.pub_date.strftime("%Y/%b/
%d").lower(),
self.slug)

class EntryAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ('title',)}

admin.site.register(Entry, EntryAdmin)
---------------------------------------------------------------------

Do anybody know what the problem is?

Cubells

unread,
Aug 24, 2008, 10:53:17 AM8/24/08
to django...@googlegroups.com

En/na marsii ha escrit:


> Hi!
> I working whit the book Practical Django Project and have a problem
> with th weblog example.
>
> (I have Django revision 8511.
>
> I got the following error when I try to add an entry:
> ---------------------------------------------------
> TypeError at /admin/coltrane/entry/add/
>
> 'module' object is not callable
>
> Request Method: POST
> Request URL: http://127.0.0.1:8000/admin/coltrane/entry/add/
> Exception Type: TypeError
> Exception Value:
>
> 'module' object is not callable
>
> Exception Location: /home/markku/django/practical_djproj/coltrane/
> models.py in save, line 76
> Python Executable: /usr/bin/python
> Python Version: 2.5.2
> ---------------------------------------------------
>
> copy of my models.py (error line 76 is marked):
>
> --------------------------------------------------
>

I have the same code, I think..., and I doesn't get that error.

Try to put comments in the whole method save() or in the line 76 so that
we can see where is the problem...

Cheers...


Cubells

unread,
Aug 24, 2008, 11:16:18 AM8/24/08
to django...@googlegroups.com

En/na marsii ha escrit:
> excerp_html = models.TextField(editable=False, blank=True)
>
_____

excerpt_html = models.TextField(editable=False, blank=True)

You have only that mistake in the code you've attached...

Your models.py works on my system.

Cheers...

Christian Joergensen

unread,
Aug 24, 2008, 11:40:43 AM8/24/08
to django...@googlegroups.com
marsii wrote:
> I working whit the book Practical Django Project and have a problem
> with th weblog example.
>
> (I have Django revision 8511.
>
> I got the following error when I try to add an entry:
> ---------------------------------------------------
> TypeError at /admin/coltrane/entry/add/
>
> 'module' object is not callable

> from markdown import markdown

[...]

> self.body_html = markdown(self.body) <-- LINE 76 ERROR

The imported name 'markdown' should be a function, yet python thinks
it's a module. What is it?

Try importing markdown and running the above snippet outside of django
in a python shell. Does that work?

Regards,
Christian

--
Christian Joergensen
http://www.technobabble.dk

marsii

unread,
Aug 26, 2008, 1:12:51 PM8/26/08
to Django users
Hi!

> En/na marsii ha escrit:> excerp_html = models.TextField(editable=False, blank=True)
> _____
> ↓
> excerpt_html = models.TextField(editable=False, blank=True)

> You have only that mistake in the code you've attached...
Thanks! I did compare the text in the book with my code, but I did'nt
see this mistake.

> Your models.py works on my system.

But I have the same error still. :-(

regards
Markku

James Bennett

unread,
Aug 26, 2008, 2:01:56 PM8/26/08
to django...@googlegroups.com
2008/8/26 marsii <ms...@telia.com>:

> But I have the same error still. :-(

I'll bet money that you have this:

import markdown

When the book tells you to do this:

from markdown import markdown

There's a very important difference.


--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

marsii

unread,
Aug 26, 2008, 2:49:08 PM8/26/08
to Django users
Hi!

>> self.body_html = markdown(self.body) <-- LINE 76 ERROR
>
> The imported name 'markdown' should be a function, yet python thinks
> it's a module. What is it?
>
> Try importing markdown and running the above snippet outside of django
> in a python shell. Does that work?

No, it does not.

But when I changed the import line to: from markdown.markdown import
markdown
then THAT error disappeared.

I looks that I made something wrong when I installed the markdown
files.

In '/usr/lib/python/site-packages' I have a link:
markdown -> /home/markku/django/markdown-1.7

and in '/home/markku/django/markdown-1.7' is file a file
'markdown.py', containing a function 'markdown'. So the same name
'markdown' is in three places!

regards
Markku
Reply all
Reply to author
Forward
0 new messages