I have an url with an optionnal argument:
urlpatterns = patterns(
'my_app.views',
url('schedule/(?P<calendar_id>\d+)/(?:month(?P<relative_month>[\+,\-]\d)/)$',
'attribute_event',name='attribute_event')
)
In my template I have a link:
{% url attribute_event calendar.id %}
But I have an error saying the url can't be reversed with these args. Must I use 2 url regex entry and url names?!
only possible if you split it into two urls:
urlpatterns = patterns('my_app.views',
url('schedule/(?P<calendar_id>\d+)/month(?P<relative_month>[\+,\-]\d)/$',
'attribute_event', name='attribute_event_relative'),
url('schedule/(?P<calendar_id>\d+)/)$',
'attribute_event', name='attribute_event'),
)
in template:
{% url attribute_event calendar.id %}
or
{% url attribute_event_relative calendar.id '+1' %}
your view:
def attribute_event(request, calendar_id, relative_month=None):
pass
Has to be this ticket:
https://code.djangoproject.com/ticket/9176
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With