Help with the url template tags

4 views
Skip to first unread message

Phil

unread,
Aug 28, 2009, 4:34:22 AM8/28/09
to Django users
Guys,

I have this error in my template when rendering my view: "Caught an
exception while rendering: Reverse for 'entry_archive_month' with
arguments '()' and keyword arguments '{'month': 8, 'year': 2009}' not
found."

I've starred at my code for too long and I can't see where the problem
lies. I'm sure it's a stupid and silly error, but I've look too much
at my code and can't seem to figure out what is happening.

Basically, the tag {% url blog:entry_archive_month
year=date.year,month=date.month %} is throwing the 'reverse for
'entry_archive_month not found'.
I've tried with args instead of kwargs (i.e.: {% url
blog:entry_archive_monthdate.year,date.month %} but without success

In another template, I have {% url blog:entry_archive_year
year=year.year %} and it works perfectly fine (and even the 'args'
version, which seems to indicate that this is some serious flaw in my
understanding of url namespace and reversing in django).

I'm just baffled and to tired to see clearly what is my stupipd
mistake.

Here is the traceback: http://dpaste.com/86470/

Here is some part of my code (the two urls.py): http://dpaste.com/hold/86487/

Can anyone help me with this one ?

Karen Tracey

unread,
Aug 28, 2009, 8:44:47 AM8/28/09
to django...@googlegroups.com
On Fri, Aug 28, 2009 at 4:34 AM, Phil <p.mar...@gmail.com> wrote:

Guys,

I have this error in my template when rendering my view: "Caught an
exception while rendering: Reverse for 'entry_archive_month' with
arguments '()' and keyword arguments '{'month': 8, 'year': 2009}' not
found."

Your urlpattern for entry_archive_month is:

url(r'^(?P<year>\d{4})/(?P<month>\d{2})/ ,
    date_based.archive_month,
    dict(entry_info_dict, month_format='%m'),
    name='entry_archive_month'),

That (since you specified {2} after the \d where you capture the month) requires exactly 2 digits in the month.  Per the error message you only have one digit in the month, so no reverse can be found for the kwargs you have specified.

Karen
 

Fil

unread,
Aug 28, 2009, 9:23:00 AM8/28/09
to Django users
I knew it was stupid !

Working now, of course.

Thx a lot Karen.

On Aug 28, 2:44 pm, Karen Tracey <kmtra...@gmail.com> wrote:

Fil

unread,
Aug 28, 2009, 9:25:08 AM8/28/09
to Django users
For the sake of completeness and in case someone with less regex-fu
that Karen, here is the correct urlpatterns:

urlpatterns = patterns('',
url(r'^$',
date_based.archive_index,
entry_info_dict,
name='entry_archive_index'),
url(r'^(?P<year>\d{4})/$',
date_based.archive_year,
dict(entry_info_dict,
make_object_list=True, template_object_name='entry'),
name='entry_archive_year'),
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/$',
date_based.archive_month,
dict(entry_info_dict, month_format='%m'),
name='entry_archive_month'),
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?
P<day>\d{1,2})/$',
date_based.archive_day,
dict(entry_info_dict, month_format='%m'),
name='entry_archive_day'),
url(r'^(?P<year>\d{4})/(?P<month>\d{1,2})/(?
P<day>\d{1,2})/(?P<slug>[-\w]+)/$',
date_based.object_detail,
dict(entry_info_dict, slug_field='slug',
month_format='%m'),
name='entry_detail'),
)
Reply all
Reply to author
Forward
0 new messages