0

How can we pass a variable from a django template tag i.e, i want to do something like this

  {{emp.get_names('a')}}

emp is the object that i am passing from my views

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

   def get_names(self,var):
      logging.debug(var)          
      names = {}
1
  • 1
    Mixing logic code with templates is a bad design principle. You should do that in a view. Why would you want that in the templates? Any reason? Commented Mar 8, 2011 at 16:20

3 Answers 3

4

You can not call a function that takes a parameter like that. Maybe writing a custom template tag can help, but, why do you need to do it in the template, but not in the view??

Custom template tags

Sign up to request clarification or add additional context in comments.

Comments

1

Django templates are designed to prevent people from doing what you are trying to do. Use a template tag.

1 Comment

Or, better still, use a view function to do this and provide the data in the template context.
0

It seems that it is not support calling the function in the default template like this.
maybe you can use some built-in tags like {{'a'|get_names}}
You can try to use Jinja2 template,which can let you write python code in it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.