Assigning Names to URL Patterns

In this case there are two URLs that call the same view function, so the reverse URL matcher (which tries to find a matching URL from a view name) gets confused, because more than one URL points to the same view.

If that is the case, you can assign names to your URL patterns, so that they all are uniquely identified:

url(r'Anetworkaddress/$', views.networkaddress_display, name='networkaddress-displaytop'), url(r'Anetworkaddress/(?P<address>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2})/$', views.networkaddress_display, name='networkaddress-display'),

Now, even though both URL pattern are calling the same function, they can be referenced individually using their unique names.

Finally, here's how the model class is going to resolve its objects' URLs:

@models.permalink def get_absolute_url(self):

return ('networkaddress-display', (),

{'address': '%s/%s' % (self.address, self.network_size)})

Was this article helpful?

0 0

Post a comment