Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

how_to_customise_a_view.rst 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. * Use custom root and local ``app.py``
  9. Example
  10. -------
  11. Create a new homepage view class in ``myproject.promotions.views`` - you can subclass
  12. Oscar's view if you like::
  13. from oscar.apps.promotions.views import HomeView as CoreHomeView
  14. class HomeView(CoreHomeView):
  15. template_name = 'promotions/new-homeview.html'
  16. In this example, we set a new template location but it's possible to customise the view
  17. in any imaginable way.
  18. If you want to change the template, create the alternative template
  19. ``new-homeview.html``. This could either be
  20. in a project-level ``templates`` folder that is added to your ``TEMPLATE_DIRS``
  21. settings, or a app-level ``templates`` folder within your 'promotions' app. For
  22. now, put something simple in there, such as::
  23. <html>
  24. <body>
  25. <p>You have successfully overridden the homepage template.</p>
  26. </body>
  27. </html>
  28. Now you can hook it up in your local ``app.py``::
  29. # myproject/promotions/app.py
  30. from oscar.apps.promotions.app import PromotionsApplication as CorePromotionsApplication
  31. from myproject.promotions.views import HomeView
  32. class PromotionsApplication(CorePromotionsApplication):
  33. home_view = HomeView
  34. application = PromotionsApplication()