473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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

11
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
1 5448
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

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

Similar topics

9
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I...
1
by: ypjofficial | last post by:
Dear All, According to OOPs , a base class pointer can to point to derived class object....call this as fact1 But somehow I am not comfortable while understanding this concept. The explanaition...
5
by: Chris Capon | last post by:
Is there any way to cast a base class object to a derived class datatype when the derived class adds no new fields nor alters the object allocation in any way? The scenario would be where you...
5
by: Randall Parker | last post by:
Using Python 2.4.2 on Windows 2000 in SPE. Getting: TypeError: 'str' object is not callable on this line: TmpErrMsg1 = "State machine %s " (StateMachineName) In Winpdb 1.0.6 the...
1
by: archana | last post by:
Hi all, I am confuse in concept of inheritance. I am having following 2 classes class base1 { public void abc() { System.Console.WriteLine("base1 abc"); }
5
by: kungfoobar | last post by:
I want to have a str with custom methods, but I have this problem: class myStr(str): def hello(self): return 'hello '+self s=myStr('world') print s.hello() # prints 'hello world'...
13
by: Rahul | last post by:
Hi Everyone, I was just playing around virtual functions and landed up with the following, class Base1 { public: virtual void sample() { printf("base::sample\n");
10
by: blangela | last post by:
If I pass a base class object by reference (likely does not make a difference here that it is passed by reference) as a parameter to a derived class member function, the member function is not...
1
by: mankeluvsit | last post by:
hey everyone, for reasons, i needed to grap information from steampowered.com from BeautifulSoup import BeautifulSoup from urllib import urlopen import re import codecs html_text =...
1
by: loren41 | last post by:
OS is Ubuntu Linux 9.10/Python Version is 2.6.4/Gui Tool is Dr. Python My program has a large html-coded string called tarr_record. When I try to open an output file and write the record to the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.