Skip to content

Instantly share code, notes, and snippets.

@arruda
Created December 6, 2012 00:28
Show Gist options
  • Save arruda/4220855 to your computer and use it in GitHub Desktop.
Save arruda/4220855 to your computer and use it in GitHub Desktop.
Django – Simple Template Tag Without a String as Argument
#-*- coding:utf-8 -*-
from django import template
register = template.Library()
from polls.models import Poll
@register.simple_tag(takes_context=True)
def get_userInfo_for_poll(context,poll, user):
context['userInfo'] = poll.getUserInfo(user)
return ''
@register.simple_tag(takes_context=True)
def current_time(context, format_string):
timezone = context['timezone']
return your_get_current_time_method(timezone, format_string)
@register.simple_tag(takes_context=True)
def current_time(context, format_string):
timezone = context['timezone']
context['newVar'] = "Hi!"
return your_get_current_time_method(timezone, format_string)
{% load polls_tags %}
{% get_userInfo_for_poll poll request.user %}
<p>Here's some info about this poll and user:{{ userInfo.someInfo }}</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment