views:

37

answers:

1

I am using url tag in my template for a view, that is used by two different urls. I am getting the wrong url in one place. Is there any way to force django to retrieve different url? Why it doesn't notify my, that such conflict occured and it doesn't know what to do (since python zen says, that is should refuse temptation to guess).

Code in template:

{% url djangoldap.views.FilterEntriesResponse Entry=entry.path as filter_url %}

Code in urls:

(r'^filter_entries/(?P<Entry>.*)/$', 
  'djangoldap.views.FilterEntriesResponse',
  {'filter_template': 'filter_entries.html',
   'results_template': 'filter_results.html'}),
(r'^choose_entries/(?P<Entry>.*)/$',
  'djangoldap.views.FilterEntriesResponse',
  {'filter_template': 'search_entries.html',
   'results_template': 'search_results.html'}),

As you can see, those two urls use the same view, but with different templates. How I can force django to retrieve former url, rather than latter?

+1  A: 

Name your URLs by adding another item to the tuple:

(r'^choose_entries/(?P<Entry>.*)/$',
  'djangoldap.views.FilterEntriesResponse',
  {'filter_template': 'search_entries.html',
   'results_template': 'search_results.html'}, 
  'sensibleprefix-choose_entries') # <-- this is the name

Then you can use the name in the URL tag.

stefanw
This works indeed. Thanks :-)
gruszczy
Along the same lines, you might also like using url() in your urlpatterns. http://docs.djangoproject.com/en/dev/topics/http/urls/#url
istruble