Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

how_to_change_a_url.rst 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. =====================================
  2. How to change an existing URL pattern
  3. =====================================
  4. Oscar has many views and associated URLs. Often you want to customised these
  5. URLs for your domain. For instance, you might want to use American spellings
  6. rather than British (``catalog`` instead of ``catalogue``).
  7. URLs in Oscar
  8. -------------
  9. Oscar's views and URLs use a tree of 'app' instances, each of which subclass
  10. ``oscar.core.application.Application`` and provide ``urls`` property. Oscar has
  11. a root app instance in ``oscar/app.py`` which can be imported into your
  12. ``urls.py``::
  13. # urls.py
  14. from oscar.app import application
  15. urlpatterns = patterns('',
  16. ... # Your other URLs
  17. (r'', include(application.urls)),
  18. )
  19. Customising
  20. -----------
  21. In order to customise Oscar's URLs, you need to use a custom app instance in
  22. your root ``urls.py`` instead of Oscar's default instance. Hence, to use
  23. ``catalog`` instead of ``catalogue``, create a subclass of Oscar's main
  24. ``Application`` class and override the ``get_urls`` method::
  25. # myproject/app.py
  26. from oscar import app
  27. class MyShop(app.Shop):
  28. # Override get_urls method
  29. def get_urls(self):
  30. urlpatterns = patterns('',
  31. (r'^catalog/', include(self.catalogue_app.urls)),
  32. ... # all the remaining URLs, removed for simplicity
  33. )
  34. return urlpatterns
  35. application = MyShop()
  36. Now modify your root ``urls.py`` to use your new application instance::
  37. # urls.py
  38. from myproject.app import application
  39. urlpatterns = patterns('',
  40. ... # Your other URLs
  41. (r'', include(application.urls)),
  42. )
  43. All URLs containing ``catalogue`` previously are now displayed as ``catalog``.