X
X
Xobb2012-04-12 16:59:13
Django
Xobb, 2012-04-12 16:59:13

Reverse() function or url template tag?

Hello,
I'm practicing with routing in Django. There is a weblog/urls.py file with the following content:

from django.conf.urls import patterns, include, url

urlpatterns = patterns('',
    url(r'^(?P<year>\d{4}/)?((?P<month>\d{2})/)?(page/(?P<page>\d+)/)?$', 'weblog.views.posts', name='home'),
)

When I load the page /, I get to the view I need, that is, the route works.
The template has the following code:
<a href="{% url home page=posts.next_page_number %}">Next</a>

Which, as I see from the stacktrace, raises an exception with the following content:
Reverse for 'home' with arguments '()' and keyword arguments '{'page': 2}' not found.

After reading about urls , I got the impression that Django programmers prefer to use several separate routes instead of my one. But then it turns out you need to write 6 variants of the reception. Is there a way to avoid this, and if so, how would I make the url template tag generate the correct url?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg, 2012-04-15
@Bahusss

Do you have the year, month, page parameters in the weblog.views.posts view as arguments?

P
Progrik, 2012-04-27
@Progrik

and in the template use this:

{% load url from future %}

? There is a suspicion that it is because of this such a thing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question