I am updating old django code from method-based views to class-based views.
I know how to include media (css/js) in forms via the Media class
How can I use the media class if my class based view does not contain any forms?
I am updating old django code from method-based views to class-based views.
I know how to include media (css/js) in forms via the Media class
How can I use the media class if my class based view does not contain any forms?
Django Sekizai is meant for this:
Here is the example from their documentation:
This example shows everything in one template, but - of course - you can split that into multiple templates either by inheritance or includes and use the
addtoblock
directives in any of the partial templates.A more complex, real life example is also in their documentation.
CSS/JS are usually managed in the template itself and not in the view. See https://docs.djangoproject.com/en/1.10/howto/static-files/
For example, use base.html:
and extend it with my_page.html:
Here is a small mixin class that can help you add Media to views based on
CreateView
,UpdateView
, andDeleteView
:Example: