Advertisement



< Prev
Next >



Django Template with Custom Class



In our last tutorial we have explained how the Django Template System uses the dot lookups strategy for list lookup. Moving on, in this tutorial we are going to explain a situation when the Django Template System uses the dot lookups strategy on encountering a dot operator with a variable name in an executing HTML template and finds a match with a method and instance variables of a custom class.




How to implement custom class lookup strategy with dot operator


The custom class lookup is implemented using the dot operator with a variables name in the HTML template file, for example - Greet.topic, Greet.get_topic, where -
Note: We need to make sure that we only call the methods that don't accept any arguments in their parameters and we don't need to include parenthesis () when calling the methods.

Let us create a Django project to explain you this situation. For those who don't know how to create a Django Project from a scratch and have not read our last tutorial, here is a recap.



Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement

Notifications



Please check our latest addition

PYTHON and DJANGO


Advertisement