Open GoogleCodeExporter opened 9 years ago
Hey Alasdair, I think this is a problem with your view, urls.py or maybe
template.
Can you post the full Traceback (the ... in the original issue report) and I
can try
to help...
Original comment by jesse.l...@gmail.com
on 12 Feb 2009 at 3:11
Jesse,
thanks for replying. I've just been exploring the syncing abilities and the
admin
screens. I haven't written any views/templates/urls for syncr flickr yet.
I'm on a different machine so can't post the full Traceback just now. I'll have
a go
trying to fix it myself.
cheers,
Alasdair
Original comment by alasdair...@gmail.com
on 12 Feb 2009 at 7:36
I second this issue. Please see my comments at issue 41 for traceback and system
setup. Very much similar.
Original comment by Prins...@gmail.com
on 17 Feb 2009 at 4:59
Here is how to reproduce the error in shell
python manage.py shell
>>> from syncr.flickr.models import Photo
>>> p = Photo.objects.all()[0]
>>> p.get_absolute_url()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.6/site-packages/django/utils/functional.py", line 55,
in _curried
File "/usr/local/lib/python2.6/site-packages/django/db/models/base.py", line 515,
in get_absolute_url
File "/usr/local/lib/python2.6/site-packages/django/db/models/__init__.py", line
30, in inner
File "/usr/local/lib/python2.6/site-packages/django/core/urlresolvers.py", line
254, in reverse
File "/usr/local/lib/python2.6/site-packages/django/core/urlresolvers.py", line
243, in reverse
NoReverseMatch: Reverse for 'photo_detail' with arguments '()' and keyword
arguments
'{'year': '2009', 'slug': u'24082008181', 'day': '31', 'month': '01'}' not
found.
Original comment by Prins...@gmail.com
on 18 Feb 2009 at 9:29
PrinsRoy - I think we need to add url patterns so that the
get_absolute_url(self)
method works for Photo and PhotoSet, but I can't get it to work.
I don't think I understand url patterns well enought to fix my problem. If
there was
a sample urls.py provided, I think I'd be able to customise it to my liking -
any
chance you could share your setup Jesse?
Below is what I've tried for the photo_detail view. I haven't touched
photoset_detail
yet.
================================================
In urls.py:
...
from sdair.views import photo_detail
urlpatterns = patterns('',
# Uncomment the next line to enable the admin:
(r'^admin/(.*)', admin.site.root),
(r'^photos/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[\w-]+)/$',
photo_detail)
)
In views.py:
from django.http import HttpResponse
def photo_detail(request,year,month,day,slug):
html = "%s %s %s: %s" % (year,month,day,slug)
return HttpResponse(html)
The url 2009/03/03/slug/ works, but when I try get_absolute_url() in the shell
I get
the following error:
python manage.py shell
Python 2.5.2 (r252:60911, Oct 5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from syncr.flickr.models import Photo
>>> p = Photo.objects.all()[0]
>>> p.get_absolute_url()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/django/utils/functional.py", line 55, in
_curried
return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
File "/usr/lib/python2.5/site-packages/django/db/models/base.py", line 515, in
get_absolute_url
return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label,
opts.module_name), func)(self, *args, **kwargs)
File "/usr/lib/python2.5/site-packages/django/db/models/__init__.py", line 30, in inner
return reverse(bits[0], None, *bits[1:3])
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 254, in
reverse
*args, **kwargs)))
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py", line 243, in
reverse
"arguments '%s' not found." % (lookup_view, args, kwargs))
NoReverseMatch: Reverse for 'photo_detail' with arguments '()' and keyword
arguments
'{'year': '2009', 'slug': u'32365-killer-sudoku', 'day': '01', 'month': '02'}'
not found.
>>>
Original comment by alasdair...@gmail.com
on 19 Feb 2009 at 12:26
This error occurs because of the permalink decorator on the model. See the
Django documentation on
permalinks here:
http://docs.djangoproject.com/en/dev/ref/models/instances/#the-permalink-decorat
or
To use it as-is, you will need a named URL pattern in your URL conf.
url(r'^photos/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[\w-]+)/$
', photo_detail,
name='photo_detail')
The flickr models are the only ones that function this way right now. These
permalink decorators are a good
idea and it would be great to apply them to the other modules. It also would
help to include a urls.py and
maybe generic views in the app.
For now, though, you can solve the issue by naming your URL pattern for detail
views with the appropriate
name (found in the get_absolute_url methods of flickr/models.py).
Original comment by jesse.l...@gmail.com
on 19 Feb 2009 at 3:55
@Jesse - Your URL pattern did the trick. Thanks for your help.
In case it helps anybody else, the equivalent URL pattern for photosets_detail
is:
url(r'^photos/sets/(?P<object_id>\d+)/$', photoset_detail,
name='photoset_detail'),
Original comment by alasdair...@gmail.com
on 19 Feb 2009 at 11:43
[deleted comment]
There is no error in get_absolute_url. The exception occurs because the model
defines a permalink using the
@permalink decorator but the name of the url pattern used in the permalink was
not defined in the urls.py file.
This results in an exception whenever anything tries to call reverse() --- as
the admin tool does. This is because
of how reverse() works (see the warning here
http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse).
reverse() analyzes all your views/urls every time it's called, so if there is
any inconsistency, it will raise this
exception.
Original comment by jesse.l...@gmail.com
on 22 Feb 2009 at 4:10
[deleted comment]
When using (date based) generic view to resolve the photo detail page, I kept
running
into 404's. Turns out that generic views take a three letter formatted month
only. To
fix this, add: 'month_format': '%m' to the photo_info_dict.
photo_info_dict = {'queryset': Photo.objects.all(),
'template_object_name':'photo', 'date_field': 'taken_date', 'month_format':
'%m'}
Nothing specific for this application, just Django behavior, but I think this
one
will catch more people off guard.
Original comment by Prins...@gmail.com
on 3 Mar 2009 at 12:55
Original issue reported on code.google.com by
alasdair...@gmail.com
on 11 Feb 2009 at 10:11