Skip to content

Instantly share code, notes, and snippets.

@shrawanx
Created April 4, 2018 09:10
Show Gist options
  • Save shrawanx/32ad1544fdca810c6bbe03961a86c553 to your computer and use it in GitHub Desktop.
Save shrawanx/32ad1544fdca810c6bbe03961a86c553 to your computer and use it in GitHub Desktop.
Dynamically rendering custom templates tags from view to template in django
def home(request):
from django.template import Context
from django.template import Template
from django.template.loader import render_to_string
x = '{% load custom_tags %} {% user_count %}'
prepare = {'tags':x}
x = render_to_string('home.html',context=prepare,request=request)
template = Template(x)
context = Context({})
y = template.render(context)
return HttpResponse(y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment