matinfo

Django templatetags remote_include

Jun 5th, 2013
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. @register.tag(name='remote_include')
  2. def do_remote_include(parser, token):
  3.     """
  4.    Remote include of an URL, replacing some variables, and caching the output for a certain amount of seconds
  5.  
  6.    {% remote_include http://remote.com/test/%s/%s/ 360 arg_1 arg_2 %}
  7.    """
  8.     bits = token.contents.split()[1:]
  9.     try:
  10.         url = bits.pop(0)
  11.     except:
  12.         raise ValueError('remote_include requires at least an URL parameter')
  13.     try:
  14.         cache_time = int(bits.pop(0))
  15.     except ValueError:
  16.         cache_time = 60
  17.     try:
  18.         args = bits[:]
  19.     except:
  20.         args = list()
  21.        
  22.     return RemoteIncludeNode(url, cache_time, args)
Advertisement
Add Comment
Please, Sign In to add comment