两个url和url标签引用的视图

发布于 2024-08-24 03:52:59 字数 747 浏览 7 评论 0原文

我在模板中使用 url 标签作为视图,该视图由两个不同的 url 使用。我在一处得到错误的网址。有没有办法强制 django 检索不同的 url?为什么它不通知我,发生了这样的冲突,并且它不知道该怎么做(因为 python zen 说,那就应该拒绝猜测的诱惑)。

模板中的代码:

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

url 中的代码:

(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'}),

如您所见,这两个 url 使用相同的视图,但使用不同的模板。我如何强制 django 检索前一个 url,而不是后者?

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>.*)/

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?

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

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?

, '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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〗斷ホ乔殘χμё〖 2024-08-31 03:52:59

通过向元组中添加另一个项目来命名您的 URL:

(r'^choose_entries/(?P<Entry>.*)/

然后您可以在 URL 标记

, 'djangoldap.views.FilterEntriesResponse', {'filter_template': 'search_entries.html', 'results_template': 'search_results.html'}, 'sensibleprefix-choose_entries') # <-- this is the name

然后您可以在 URL 标记

Name your URLs by adding another item to the tuple:

(r'^choose_entries/(?P<Entry>.*)/

Then you can use the name in the URL tag.

, '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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文