Sunday, February 8, 2015

Switch Case in Python


This is for my understanding and memory I  need to write about the Python way of writing switch case. One such way is writing the if elif and else construct but the other way as mentioned in the some of the code I have seen as is to use the dictionary as key value pair and match the key of the dictionary key as a case value and return the same from the dictionary.


The solution below explains the logic for the same and do keep in mind why this is working out because

  • For the dictionary a = {key:value}  the expression a[key]  and {key:value}[key] are same and will give out value

Saturday, February 7, 2015

How to Conditionally execute a javascript/jquery snippet in django templates


Many times in a project while rendering html on django template we need to execute certain Javascript code to conditionally render some html component based on the value of some template variable. Using if else conditions provided by django template system was not working , then how to go about this conditional execution of script


The code snippet below gives the hint