You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Django-Oscar中实现页面内部重定向?无需修改urls.py与views.py

Got it! Since you want to avoid modifying urls.py or views.py in Django-Oscar, the cleanest approach is to override the navbar template to adjust the link's target directly. Here's a step-by-step breakdown:

  • First, locate the default navbar template in Django-Oscar's core files. Typically, this lives at oscar/templates/oscar/partials/navbar.html (the exact path might vary slightly based on your Oscar version, but it'll be under the oscar/partials template directory).
  • In your Django project's templates folder, create a matching directory structure to override the template: your_project/templates/oscar/partials/.
  • Copy the entire content of the original navbar.html into this new directory's navbar.html file.
  • Find the line that renders the "Product" link. It’ll look something like this:
    <a href="{% url 'catalogue:index' %}" class="nav-link">Product</a>
    
  • Replace the href value with the URL name of your Services page. For example, if your Services page uses the URL name oscar:services (adjust this to match your actual URL name), update it to:
    <a href="{% url 'oscar:services' %}" class="nav-link">Product</a>
    
  • Save the modified template, restart your Django development server, and test the link—clicking "Product" will now take you straight to the Services page.

This method leverages Django-Oscar’s built-in template overriding system, which is the recommended way to customize the framework without altering core files like urls.py or views.py.

内容的提问来源于stack exchange,提问作者david johnson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:41:36