Monday, April 29, 2013

Access request object in a custom template tag

Hello,

I am currently writing a custom template tag and I need to access the request object within the tag code.
When using tag helpers (simple_tag, inclusion_tag and assignment_tag) you can register them with an additional takes_context=True parameter that makes the request object available.
But this does not work with the low level tag decorator:

@register.tag(takes_context=True)  def mytag(parser, token):     ...
raises the exception:  tag() got an unexpected keyword argument 'takes_context'

2 questions :

- is there a reason why the tag decorator does accept the takes_context argument ?
- how can I access the template context with this decorator (and thus the request object) ?


Thanks a lot.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment