I’m building a django application that has similar-looking display elements on several different pages.
For example, the projects.html page has a table that lists projects and some related information; the documents.html page has a similar-looking table
It seems like there ought to be a way to define a “my_kind_of_table” template and then insert it into different pages as necessary:
{% proj_list | create_my_kind_of_table:name,description,last_update %}
and then…
{% doc_list | create_my_kind_of_table:name,header,owner %}
I suspect that django can already do this, but I don’t know what to search for. Any suggestions?
How about
{% include ... %}?To add context variables that all tables needs, then you have three solutions to pick: One is what I would call the “old fashioned” way, and is to have special function that is called by all views that needs to add context function. The second is to create a function decorator, that is used on the function that returns the response. The third way can be used if you use the new 1.3 class-based views, then you can create a mixin-class that your view-class inherits, and that adds these things in its own
getmethod.