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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imhomer
    New Member
    • Feb 2012
    • 11

    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:
    Code:
    from django.db import models
    from django.contrib.auth.models import User
    from django.contrib import admin
    
    class Album(models.Model):
        title = models.CharField(max_length=60)
        public = models.BooleanField(default=False)
        def __unicode__(self):
            return self.title
    
    class Tag(models.Model):
        tag = models.CharField(max_length=50)
        def __unicode__(self):
            return self.tag
    
    class Image(models.Model):
        title = models.CharField(max_length=60, blank=True, null=True)
        image = models.FileField(upload_to="images/")
        tags = models.ManyToManyField(Tag, blank=True)
        albums = models.ManyToManyField(Album, blank=True)
        created = models.DateTimeField(auto_now_add=True)
        rating = models.IntegerField(default=50)
        width = models.IntegerField(blank=True, null=True)
        height = models.IntegerField(blank=True, null=True)
        user = models.ForeignKey(User, null=True, blank=True)
    
        def __unicode__(self):
            return self.image.name
    
    class AlbumAdmin(admin.ModelAdmin):
        search_fields = ["title"]
        list_display = ["title"]
    
    class TagAdmin(admin.ModelAdmin):
        list_display = ["tag"]
    
    class ImageAdmin(admin.ModelAdmin):
        search_fields = ["title"]
        list_display = ["__unicode__", "title", "user", "rating", "created"]
        list_filter = ["tags", "albums"]
    
    admin.site.register(Album, AlbumAdmin)
    admin.site.register(Tag, TagAdmin)
    admin.site.register(Image, ImageAdmin)
    photo/views.py:
    Code:
    from django.http import HttpResponseRedirect, HttpResponse
    from django.shortcuts import get_object_or_404, render_to_response
    from django.contrib.auth.decorators import login_required
    from django.core.context_processors import csrf
    from django.core.paginator import Paginator, InvalidPage, EmptyPage
    from django.forms import ModelForm
    from settings import MEDIA_URL
    
    from dbe.photo.models import *
    
    def main(request):
        """Main listing."""
        albums = Album.objects.all()
        if not request.user.is_authenticated():
            albums = albums.filter(public=True)
    
        paginator = Paginator(albums, 10)
        try: page = int(request.GET.get("page", '1'))
        except ValueError: page = 1
    
        try:
            albums = paginator.page(page)
        except (InvalidPage, EmptyPage):
            albums = paginator.page(paginator.num_pages)
    
        for album in albums.object_list:
            album.images = album.image_set.all()[:4]
    
        return render_to_response("photo/list.html", dict(albums=albums, user=request.user,
            media_url=MEDIA_URL))
    Main urls.py:
    Code:
    from django.conf.urls.defaults import patterns, include, url
    
    
    
    # Uncomment the next two lines to enable the admin:
    
    from django.contrib import admin
    
    admin.autodiscover()
    
    
    
    urlpatterns = patterns('',
    
        # Examples:
    
        # url(r'^$', 'SoEasy.views.home', name='home'),
    
        # url(r'^SoEasy/', include('SoEasy.foo.urls')),
    
    
    
        # Uncomment the admin/doc line below to enable admin documentation:
    
        # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    
    
    
        # Uncomment the next line to enable the admin:
    
        url(r'^admin/', include(admin.site.urls)),
        url(r"", "main"),
    )
    I really hope someone could help me solve the problem! Thanks!
  • andrean
    New Member
    • May 2012
    • 5

    #2
    your urls.py has the error,
    url(r"", "main"),

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

    or import the views module and

    url(r"", views.main),

    Comment

    Working...