'str' object is not callable in base.py

184 views
Skip to first unread message

Lachlan Musicman

unread,
Sep 4, 2012, 12:29:59 AM9/4/12
to django...@googlegroups.com
Hi all,

Stumped on this one:


Traceback:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/tafe/timetable/2012-4/

Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'tafe',
'south',
'crispy_forms')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')

Traceback:
File "/home/datakid/src/envs/mlhrd/local/lib/python2.7/site-packages/django/core/handlers/base.py"
in get_response
111. response = callback(request,
*callback_args, **callback_kwargs)

Exception Type: TypeError at /tafe/timetable/2012-4/
Exception Value: 'str' object is not callable

urls.py:
...
url(r'^timetable/(?P<slug>[-\w]+)/$', 'timetable_view'),
...

views.py:
@login_required
def timetable_view(request, slug):
timetable = get_object_or_404(slug=slug)
sessions = timetable.sessions.all()
return render_to_response('tafe/timetable_detail.html',{'timetable':timetable,'sessions':sessions})

models.py:

class Session(models.Model):
...
timetable = models.ForeignKey(Timetable, related_name='sessions')
...

What am I doing wrong?

cheers
L.

zayatzz

unread,
Sep 4, 2012, 2:06:08 AM9/4/12
to django...@googlegroups.com
From this post i can see this line beeing wrong . 

timetable = get_object_or_404(slug=slug) 

You also need to give object as one of the parameters for get_object_or_404 shortcut: like this :

Bill Freeman

unread,
Sep 4, 2012, 5:17:00 PM9/4/12
to django...@googlegroups.com
My best guess is that, for whatever reason, 'timetable_view' in your url conf
has not been converted into the view function. Try actually importing the
view in urls.py and putting it as the target of the pattern *without*
the quotes.
If this works, then figuring out whether you needed 'app_name.timetable_view'
or some such is where to look. If it still doesn't work, you may get additional
insights (can you actually import views.py, or does it have a syntax
error, etc.).
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/gEKT5Z85E14J.
>
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

Lachlan Musicman

unread,
Sep 4, 2012, 9:11:58 PM9/4/12
to django...@googlegroups.com
On Tuesday, September 4, 2012, zayatzz wrote:
From this post i can see this line beeing wrong . 

timetable = get_object_or_404(slug=slug) 

You also need to give object as one of the parameters for get_object_or_404 shortcut: like this :

Thankyou for pointing this out - it was indeed wrong and has now been fixed. Unfortunately, it didn't solve the problem.

cheers
L. 

Lachlan Musicman

unread,
Sep 4, 2012, 9:21:19 PM9/4/12
to django...@googlegroups.com
On Wednesday, September 5, 2012, Bill Freeman wrote:
My best guess is that, for whatever reason, 'timetable_view' in your url conf
has not been converted into the view function.  Try actually importing the
view in urls.py and putting it as the target of the pattern *without*
the quotes.
If this works, then figuring out whether you needed 'app_name.timetable_view'
or some such is where to look.  If it still doesn't work, you may get additional
insights (can you actually import views.py, or does it have a syntax
error, etc.).

Yes, this was the answer - thanks Bill.

I tried tafe.timetable_view and it didn't work, so I tried  

from tafe.views import timetable_view

and it did...

then I realised I needed

'tafe.views..timetable_view'
 as the pattern target.

Thanks for your help
L.
Reply all
Reply to author
Forward
0 new messages