Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

how_to_change_a_url.rst 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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
  12. Example
  13. -------
  14. In order to customise Oscar's URLs, you need to use a custom app instance in
  15. your root ``urls.py`` instead of Oscar's default instance. Hence, to use
  16. ``catalog`` instead of ``catalogue``, create a subclass of Oscar's main
  17. ``Application`` class and override the ``get_urls`` method::
  18. # myproject/app.py
  19. from oscar import app
  20. class MyShop(app.Shop):
  21. # Override get_urls method
  22. def get_urls(self):
  23. urlpatterns = patterns('',
  24. (r'^catalog/', include(self.catalogue_app.urls)),
  25. ... # all the remaining URLs, removed for simplicity
  26. )
  27. return urlpatterns
  28. application = MyShop()
  29. Now modify your root ``urls.py`` to use your new application instance::
  30. # urls.py
  31. from myproject.app import application
  32. urlpatterns = patterns('',
  33. ... # Your other URLs
  34. (r'', include(application.urls)),
  35. )
  36. All URLs containing ``catalogue`` previously are now displayed as ``catalog``.