You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

how_to_change_a_url.rst 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. =====================================
  2. How to change an existing URL pattern
  3. =====================================
  4. Oscar has many views and associated URLs. Often you want to customise these
  5. URLs for your domain. For instance, you might want to use American spellings
  6. rather than British (``catalog`` instead of ``catalogue``).
  7. This How-to describes how to do just that.
  8. It builds upon the steps described in :doc:`/topics/customisation`. Please
  9. read it first and ensure that you've:
  10. * Created a Python module with the the same label
  11. * Added it as Django app to ``INSTALLED_APPS``
  12. * Created a custom ``app.py``
  13. Example
  14. -------
  15. In order to customise Oscar's URLs, you need to use a custom app instance
  16. instead of Oscar's default instance. ``/catalogue`` is wired up in the root
  17. application, so we need to replace that. Hence, to use
  18. ``catalog`` instead of ``catalogue``, create a subclass of Oscar's main
  19. ``Application`` class and override the ``get_urls`` method::
  20. # myproject/app.py
  21. from oscar import app
  22. class MyShop(app.Shop):
  23. # Override get_urls method
  24. def get_urls(self):
  25. urlpatterns = patterns('',
  26. (r'^catalog/', include(self.catalogue_app.urls)),
  27. ... # all the remaining URLs, removed for simplicity
  28. )
  29. return urlpatterns
  30. application = MyShop()
  31. Now modify your root ``urls.py`` to use your new application instance::
  32. # urls.py
  33. from myproject.app import application
  34. urlpatterns = patterns('',
  35. ... # Your other URLs
  36. (r'', include(application.urls)),
  37. )
  38. All URLs containing ``catalogue`` previously are now displayed as ``catalog``.
  39. If you wanted to change URLs of a sub-app (e.g. ``/catalogue/category/``),
  40. you only need to replace the ``catalogue`` app. There's no need to change
  41. your ``urls.py`` or touch the root ``application`` instance. ``application``
  42. instances dynamically load their sub-apps, so it just pick up your replacement::
  43. # oscar/app.py
  44. class Shop(Application):
  45. name = None
  46. catalogue_app = get_class('catalogue.app', 'application')
  47. customer_app = get_class('customer.app', 'application')
  48. ...