I met this problem (Django base.py: 'str' object is not callable) when I go through a Django tutorial:
photo/models.py: - 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: - 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: - 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!
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),
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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");
}
|
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'...
|
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");
|
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...
|
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 =...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |