fork download
  1.  
  2. import jinja2
  3. from jinja2 import Environment, meta
  4.  
  5. # Define the template string
  6. template_string = "Found the BGP established with PEER IP {{peer_ip}}"
  7.  
  8. # Create a Jinja2 Environment
  9. env = Environment()
  10.  
  11. # Parse the template string to extract variable names
  12. parsed_content = env.parse(template_string)
  13. variable_names = meta.find_undeclared_variables(parsed_content)
  14.  
  15. # Print the extracted variable names
  16. print("Variable names:", variable_names)
  17.  
Success #stdin #stdout 0.07s 15180KB
stdin
Standard input is empty
stdout
('Variable names:', set(['peer_ip']))