467,145 Members | 1,083 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,145 developers. It's quick & easy.

Django base.py: 'str' object is not callable

I met this problem (Django base.py: 'str' object is not callable) when I go through a Django tutorial:

photo/models.py:
Expand|Select|Wrap|Line Numbers
  1. from django.db import models
  2. from django.contrib.auth.models import User
  3. from django.contrib import admin
  4.  
  5. class Album(models.Model):
  6.     title = models.CharField(max_length=60)
  7.     public = models.BooleanField(default=False)
  8.     def __unicode__(self):
  9.         return self.title
  10.  
  11. class Tag(models.Model):
  12.     tag = models.CharField(max_length=50)
  13.     def __unicode__(self):
  14.         return self.tag
  15.  
  16. class Image(models.Model):
  17.     title = models.CharField(max_length=60, blank=True, null=True)
  18.     image = models.FileField(upload_to="images/")
  19.     tags = models.ManyToManyField(Tag, blank=True)
  20.     albums = models.ManyToManyField(Album, blank=True)
  21.     created = models.DateTimeField(auto_now_add=True)
  22.     rating = models.IntegerField(default=50)
  23.     width = models.IntegerField(blank=True, null=True)
  24.     height = models.IntegerField(blank=True, null=True)
  25.     user = models.ForeignKey(User, null=True, blank=True)
  26.  
  27.     def __unicode__(self):
  28.         return self.image.name
  29.  
  30. class AlbumAdmin(admin.ModelAdmin):
  31.     search_fields = ["title"]
  32.     list_display = ["title"]
  33.  
  34. class TagAdmin(admin.ModelAdmin):
  35.     list_display = ["tag"]
  36.  
  37. class ImageAdmin(admin.ModelAdmin):
  38.     search_fields = ["title"]
  39.     list_display = ["__unicode__", "title", "user", "rating", "created"]
  40.     list_filter = ["tags", "albums"]
  41.  
  42. admin.site.register(Album, AlbumAdmin)
  43. admin.site.register(Tag, TagAdmin)
  44. admin.site.register(Image, ImageAdmin)
photo/views.py:
Expand|Select|Wrap|Line Numbers
  1. from django.http import HttpResponseRedirect, HttpResponse
  2. from django.shortcuts import get_object_or_404, render_to_response
  3. from django.contrib.auth.decorators import login_required
  4. from django.core.context_processors import csrf
  5. from django.core.paginator import Paginator, InvalidPage, EmptyPage
  6. from django.forms import ModelForm
  7. from settings import MEDIA_URL
  8.  
  9. from dbe.photo.models import *
  10.  
  11. def main(request):
  12.     """Main listing."""
  13.     albums = Album.objects.all()
  14.     if not request.user.is_authenticated():
  15.         albums = albums.filter(public=True)
  16.  
  17.     paginator = Paginator(albums, 10)
  18.     try: page = int(request.GET.get("page", '1'))
  19.     except ValueError: page = 1
  20.  
  21.     try:
  22.         albums = paginator.page(page)
  23.     except (InvalidPage, EmptyPage):
  24.         albums = paginator.page(paginator.num_pages)
  25.  
  26.     for album in albums.object_list:
  27.         album.images = album.image_set.all()[:4]
  28.  
  29.     return render_to_response("photo/list.html", dict(albums=albums, user=request.user,
  30.         media_url=MEDIA_URL))
Main urls.py:
Expand|Select|Wrap|Line Numbers
  1. from django.conf.urls.defaults import patterns, include, url
  2.  
  3.  
  4.  
  5. # Uncomment the next two lines to enable the admin:
  6.  
  7. from django.contrib import admin
  8.  
  9. admin.autodiscover()
  10.  
  11.  
  12.  
  13. urlpatterns = patterns('',
  14.  
  15.     # Examples:
  16.  
  17.     # url(r'^$', 'SoEasy.views.home', name='home'),
  18.  
  19.     # url(r'^SoEasy/', include('SoEasy.foo.urls')),
  20.  
  21.  
  22.  
  23.     # Uncomment the admin/doc line below to enable admin documentation:
  24.  
  25.     # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
  26.  
  27.  
  28.  
  29.     # Uncomment the next line to enable the admin:
  30.  
  31.     url(r'^admin/', include(admin.site.urls)),
  32.     url(r"", "main"),
  33. )
I really hope someone could help me solve the problem! Thanks!
Mar 31 '12 #1
  • viewed: 4262
Share:
1 Reply
your urls.py has the error,
url(r"", "main"),

change it to:
url(r"", "yourprojectname.views.main"),

or import the views module and

url(r"", views.main),
May 17 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by justanotherguy63@yahoo.com | last post: by
1 post views Thread by ypjofficial@indiatimes.com | last post: by
5 posts views Thread by Randall Parker | last post: by
5 posts views Thread by kungfoobar@gmail.com | last post: by
13 posts views Thread by Rahul | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.