On Sun, Oct 16, 2011 at 6:07 AM, Tsung-Hsien <jasoniem9...@gmail.com> wrote: > I have a photo page needed connecting each photo to different URL. > > ---------------------------------------------------------- > The URL as below: > url(r'^gallery/(?P<item_id>\d+)/(?P<photo_id>\d+)/$', zoom_photo) > > The view as below: > def zoom_photo(request, item_id, photo_id): > item = Item.objects.get(id=item_id) > photo = item.photo_set.all[photo_id]
You forgot the call the all() method here. photo = item.photo_set.all()[photo_id] Be aware this will only be reliable if you have a stable order_by defined, so the index is always across the same sorting of the photos. > t = loader.get_template("zoom_photo.html") > c = Context({'photo':photo}) > return HttpResponse(t.render(c)) > > ------------------------------------------------------------ > When I enter the URL such as http://127.0.0.1:8000/blog/gallery/1/1/ > it shows a error > Exception Type: TypeError > Exception Value: > 'instancemethod' object is not subscriptable > Exception Location: C:\Python27\Lib\site-packages\django\bin\mysite\.. > \mysite\blog\views.py in zoom_photo, line 27 > > ----------------------------------------------------------- > In the first, I think change the photo_id to int(photo_id), but the > error is the same as above. I have no idea how to solve. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://techblog.ironfroggy.com/ Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.