print referred variable from object in django/python

By : Rajeev

In the below python code ,can the object know that the template tag is referring a variable and get that in a python variable

newemp is the object that i am passing from the views and the template is trying to access a variable as {{newemp.get_names.emp_add}} ,now in the python code can the object print this variable i.e, emp_add

class Emp(models.Model):
   name = models.CharField(max_length=255, unique=True)
   address1 = models.CharField(max_length=255)

   def get_names(self):
      var=self.some referred object

     names = {}
By : Rajeev


No. The access is done once the appropriate object has been returned from get_names() so there is no direct way to know within the method what is being accessed.

If you are asking whether you can write to a variable within a template, and then access that value back within your Python code, I do not believe so. That kind of goes against the idea of templates, IMHO.

By : dappawit

This video can help you solving your question :)
By: admin