Reverse() function or the url template tag?


Practicing with routing with new interface in Django. There is a file weblog/ follows:

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

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

When you load the page, then I get on my desired view, ie Raut works.

The template has the following code:

<a href="{% url home page=posts.next_page_number %}">Next</a>

Which, as I see stacktrace raises exception with the following content:

Reverse for 'home' with arguments '()' and keyword arguments '{'page': 2}' not found.

After reading about the URLs I was under the impression that Django programmers prefer to use several separate events instead of my one. But then it turns out you need to write 6 versions of the events. Is there a possibility to avoid it and, if so, how to make a template tag url correctly formed url?
October 8th 19 at 00:13
3 answers
October 8th 19 at 00:15
There is a suspicion that in the pattern you need to pass all the parameters, i.e.

<a href="{% url home year=..., month=... page=posts.next_page_number %}">Next</a>
I tried to do so, unfortunately further indicates that router such is not present. - Frida_Mayer commented on October 8th 19 at 00:18
October 8th 19 at 00:17
And you have in view a weblog.views.posts parameters year, month, page — specified as arguments?
Yes. They are listed as arguments. I read stackoverflow on this subject( 1, 2 ) and realized that Django likes lots and lots of bashes for each possible set of parameters. That's only will have to have a template for each option: without the year and the pages, without years but with the page with the year and page by year and month, and page. Something like that. - Frida_Mayer commented on October 8th 19 at 00:20
October 8th 19 at 00:19
and in the template to try and use this:
{% load url from future %}

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

Find more questions by tags Django