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_customise_a_view.rst 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. =======================
  2. How to customise a view
  3. =======================
  4. Oscar has many views. This How-to describes how to customise one of them for
  5. your project. It builds upon the steps described in
  6. :doc:`/topics/customisation`. Please read it first and ensure that you've:
  7. * Created a Python module with the the same label
  8. * Added it as Django app to ``INSTALLED_APPS``
  9. * Use custom ``app.py``
  10. Example
  11. -------
  12. Create a new homepage view class in ``myproject.promotions.views`` - you can subclass
  13. Oscar's view if you like::
  14. from oscar.apps.promotions.views import HomeView as CoreHomeView
  15. class HomeView(CoreHomeView):
  16. template_name = 'promotions/new-homeview.html'
  17. In this example, we set a new template location but it's possible to customise the view
  18. in any imaginable way.
  19. If you want to change the template, create the alternative template
  20. ``new-homeview.html``. This could either be
  21. in a project-level ``templates`` folder that is added to your ``TEMPLATE_DIRS``
  22. settings, or a app-level ``templates`` folder within your 'promotions' app. For
  23. now, put something simple in there, such as::
  24. <html>
  25. <body>
  26. <p>You have successfully overridden the homepage template.</p>
  27. </body>
  28. </html>
  29. Now you can hook it up in your local ``app.py``::
  30. # myproject/promotions/app.py
  31. from oscar.apps.promotions.app import PromotionsApplication as CorePromotionsApplication
  32. from myproject.promotions.views import HomeView
  33. class PromotionsApplication(CorePromotionsApplication):
  34. home_view = HomeView
  35. application = PromotionsApplication()